2 // System.Drawing.Test.LineLayout.jvm.cs
5 // Konstantin Triger <kostat@mainsoft.com>
7 // Copyright (C) 2005 Mainsoft Corporation, (http://www.mainsoft.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Drawing.Drawing2D;
32 using font = java.awt.font;
\r
33 using text = java.text;
34 using awt = java.awt;
\r
35 using geom = java.awt.geom;
37 namespace System.Drawing.Text {
39 internal sealed class LineLayout {
43 readonly font.TextLayout _layout;
45 readonly float _accumulatedHeight;
46 readonly TextLineIterator _lineIter;
52 internal LineLayout(font.TextLayout layout,
53 TextLineIterator lineIter,
54 float accumulatedHeight) {
58 _accumulatedHeight = accumulatedHeight;
65 internal float AccumulatedHeight {
66 get { return _accumulatedHeight; }
69 internal float MeasureWidth {
\r
71 return Width + (_lineIter.Margin*2);
\r
75 internal int CharacterCount {
76 get { return _layout.getCharacterCount(); }
79 internal float Ascent {
80 get { return _layout.getAscent(); }
83 internal float Descent {
84 get { return _layout.getDescent(); }
87 public float Leading {
88 get { return _layout.getLeading(); }
91 internal float NativeY {
\r
93 if (_lineIter.Format.IsVertical) {
\r
94 float height = _lineIter.Height;
\r
95 if (float.IsPositiveInfinity(height))
\r
97 switch (_lineIter.Format.Alignment) {
\r
98 case StringAlignment.Center:
\r
99 return (height - Width) / 2;
\r
100 case StringAlignment.Far:
\r
101 return height - _layout.getVisibleAdvance() - _lineIter.Margin;
\r
103 return _lineIter.Margin;
\r
107 return AccumulatedHeight + Ascent;
\r
111 internal float NativeX {
\r
113 float width = _lineIter.Width;
\r
114 if (float.IsPositiveInfinity(width))
\r
116 if (_lineIter.Format.IsVertical)
\r
117 return (_lineIter.Format.IsRightToLeft) ?
\r
118 width - AccumulatedHeight - Ascent :
\r
119 AccumulatedHeight + Leading + Descent;
\r
122 switch ( _lineIter.Format.Alignment) {
\r
123 case StringAlignment.Center:
\r
124 xOffset = (width - Width) / 2;
\r
126 case StringAlignment.Far:
\r
127 if (_lineIter.Format.IsRightToLeft)
\r
128 xOffset = _lineIter.Margin;
\r
130 xOffset = width - _layout.getVisibleAdvance() - _lineIter.Margin;
\r
133 if (_lineIter.Format.IsRightToLeft)
\r
134 xOffset = width - _layout.getVisibleAdvance() - _lineIter.Margin;
\r
136 xOffset = _lineIter.Margin;
\r
145 internal float Height {
\r
147 return Ascent + Descent + Leading;
\r
151 internal float Width {
\r
153 if (_lineIter.Format.MeasureTrailingSpaces)
154 if (!(_lineIter.Format.IsRightToLeft ^
155 (_lineIter.Format.Alignment == StringAlignment.Far)))
156 return _layout.getAdvance();
158 return _layout.getVisibleAdvance();
166 internal void Draw(awt.Graphics2D g2d, float x, float y) {
\r
167 if (_lineIter.Format.IsVertical)
\r
168 _layout.draw(g2d, y + NativeY, -(x + NativeX) );
\r
170 _layout.draw(g2d, x + NativeX, y + NativeY );
\r
173 internal awt.Shape GetOutline(float x, float y) {
\r
174 geom.AffineTransform t = (geom.AffineTransform) _lineIter.Transform.MemberwiseClone ();
\r
176 if (_lineIter.Format.IsVertical)
\r
177 t.translate(y + NativeY, -(x + NativeX));
\r
179 t.translate(x + NativeX, y + NativeY);
\r
181 return _layout.getOutline(t);
\r