internal LineLayout(font.TextLayout layout, TextLineIterator lineIter, float accumulatedHeight) { _layout = layout; _lineIter = lineIter; _accumulatedHeight = accumulatedHeight; }
SizeF MeasureString (string text, Font font, StringFormat format, float width, float height, int[] statistics) { if (statistics != null) { statistics[0] = 0; statistics[1] = 0; } TextLineIterator iter = new TextLineIterator(text, font, NativeObject.getFontRenderContext(), format, width, height); float mwidth = 0; int linesFilled = 0; for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) { linesFilled ++; float w = layout.MeasureWidth; if (w > mwidth) mwidth = w; } if (linesFilled == 0) return SizeF.Empty; float mheight = iter.AccumulatedHeight; if (format != null) { if (format.IsVertical) { float temp = mheight; mheight = mwidth; mwidth = temp; } } if (!(format != null && format.NoClip)) { if (mwidth > width) mwidth = width; if (mheight > height) mheight = height; } if (statistics != null) { statistics[0] = linesFilled; statistics[1] = iter.CharsConsumed; } return new SizeF (mwidth / UnitConversion [(int) _pageUnit], mheight / UnitConversion [(int) _pageUnit]); }
public Region [] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat) { if (stringFormat == null) throw new ArgumentException("stringFormat"); CharacterRange[] ranges = stringFormat.CharRanges; if (ranges == null || ranges.Length == 0) return new Region[0]; GraphicsPath[] pathes = new GraphicsPath[ranges.Length]; for (int i = 0; i < pathes.Length; i++) pathes[i] = new GraphicsPath(); TextLineIterator iter = new TextLineIterator(text, font, NativeObject.getFontRenderContext(), stringFormat, layoutRect.Width, layoutRect.Height); for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) { for (int i = 0; i < ranges.Length; i++) { int start = ranges[i].First; int length = ranges[i].Length; start -= iter.CharsConsumed; int limit = start + length; int layoutStart = iter.CurrentPosition - layout.CharacterCount; if (start < iter.CurrentPosition && limit > layoutStart) { float layoutOffset; if (start > layoutStart) layoutOffset = iter.GetAdvanceBetween(layoutStart, start); else { layoutOffset = 0; start = layoutStart; } float width = (limit < iter.CurrentPosition) ? iter.GetAdvanceBetween(start, limit) : layout.Width - layoutOffset; float height = layout.Ascent + layout.Descent; float x = layout.NativeX; float y = layout.NativeY; if (stringFormat.IsVertical) { y += layoutOffset; x -= layout.Descent; } else { x += layoutOffset; y -= layout.Ascent; } if (layout.AccumulatedHeight + height > iter.WrapHeight) { float diff = iter.WrapHeight - layout.AccumulatedHeight; if (stringFormat.IsVertical && stringFormat.IsRightToLeft) { x += diff; height -= diff; } else height = diff; } if (stringFormat.IsVertical) pathes[i].AddRectangle(x + layoutRect.X, y + layoutRect.Y, height, width); else pathes[i].AddRectangle(x + layoutRect.X, y + layoutRect.Y, width, height); } } } geom.AffineTransform lineAlignT = iter.CalcLineAlignmentTransform(); if (lineAlignT != null) { for (int i = 0; i < pathes.Length; i++) pathes[i].NativeObject.transform(lineAlignT); } Region[] regions = new Region[ranges.Length]; for (int i = 0; i < regions.Length; i++) regions[i] = new Region(pathes[i]); return regions; }
void DrawString (string s, Font font, Brush brush, float x, float y, float width, float height, StringFormat format) { if (brush == null) throw new ArgumentNullException("brush"); if (font == null) throw new ArgumentNullException("font"); if (format != null && format.LineAlignment != StringAlignment.Near) { SizeF sizeF = MeasureString(s, font, format, width, height, null); float lineAWidth = width; float lineAHeight = height; if (float.IsPositiveInfinity(width)) lineAWidth = lineAHeight = 0; float wdelta = format.IsVertical ? lineAWidth - sizeF.Width : lineAHeight - sizeF.Height; float pdelta = format.LineAlignment == StringAlignment.Center ? wdelta/2 : wdelta; if (format.IsVertical) { if (!(format.IsRightToLeft && format.LineAlignment == StringAlignment.Far)) x += pdelta; if (!float.IsPositiveInfinity(width)) width -= wdelta; } else { y += pdelta; if (!float.IsPositiveInfinity(width)) height -= wdelta; } } awt.Paint oldP = NativeObject.getPaint(); NativeObject.setPaint(brush); try { geom.AffineTransform oldT = NativeObject.getTransform(); try { bool noclip = float.IsPositiveInfinity(width) || (format != null && format.NoClip); awt.Shape oldClip = null; if (!noclip) { oldClip = NativeObject.getClip(); NativeObject.clip(new geom.Rectangle2D.Float(x, y, width, height)); } try { TextLineIterator iter = new TextLineIterator(s, font, NativeObject.getFontRenderContext(), format, width, height); NativeObject.transform(iter.Transform); for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) { layout.Draw (NativeObject, x * UnitConversion [(int) PageUnit], y * UnitConversion [(int) PageUnit]); } } finally { if (!noclip) NativeObject.setClip(oldClip); } } finally { NativeObject.setTransform(oldT); } } finally { NativeObject.setPaint(oldP); } }
void AddString (string s, Font font, float x, float y, float width, float height, StringFormat format) { TextLineIterator iter = new TextLineIterator(s, font, new java.awt.font.FontRenderContext(null, false, false), format, width, height); int coordsCount = NativeObject.CoordsCount; for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) { NativeObject.append(layout.GetOutline(x, y), false); } AffineTransform lineAlignT = iter.CalcLineAlignmentTransform(); if (lineAlignT != null) NativeObject.transform(lineAlignT, coordsCount, NativeObject.CoordsCount - coordsCount); }