|
|
@@ -407,175 +407,6 @@ namespace System.Drawing {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- internal SizeF MeasureDraw (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format, bool fDraw) {
|
|
|
- SizeF retVal = new SizeF(0,0);
|
|
|
- awt.Graphics2D g = NativeObject;
|
|
|
-
|
|
|
- java.awt.Font fnt = font.NativeObject;
|
|
|
- if(s != null && s.Length != 0 && fnt != null) {
|
|
|
- float size = fnt.getSize();
|
|
|
- float wid = layoutRectangle.Width;
|
|
|
- float hei = layoutRectangle.Height;
|
|
|
- float x = layoutRectangle.X;
|
|
|
- float y = layoutRectangle.Y;
|
|
|
- java.text.AttributedString astr = new java.text.AttributedString(s);
|
|
|
- astr.addAttribute(java.awt.font.TextAttribute.FONT, fnt);
|
|
|
- java.text.AttributedCharacterIterator prg = astr.getIterator();
|
|
|
- java.awt.font.TextLayout textlayout = new java.awt.font.TextLayout(prg, g.getFontRenderContext());
|
|
|
- int prgStart = prg.getBeginIndex();
|
|
|
- int prgEnd = prg.getEndIndex();
|
|
|
- java.awt.font.LineBreakMeasurer lineMeasurer = new java.awt.font.LineBreakMeasurer(
|
|
|
- prg, new java.awt.font.FontRenderContext(null, false, false));
|
|
|
- lineMeasurer.setPosition(prgStart);
|
|
|
- float formatWidth = wid;
|
|
|
-
|
|
|
- //some vertical layout magic - should be reviewed
|
|
|
- // if(format != null)
|
|
|
- // {
|
|
|
- // StringFormatFlags formatflag = format.FormatFlags;
|
|
|
- // if(formatflag != StringFormatFlags.DirectionVertical)
|
|
|
- // {
|
|
|
- // if(size > (float)8 && wid > (float)13)
|
|
|
- // formatWidth = wid - (float)12;
|
|
|
- // if(formatflag == StringFormatFlags.DirectionRightToLeft && size == (float)6)
|
|
|
- // formatWidth = wid - (float)10;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- //now calculate number of lines and full layout height
|
|
|
- //this is required for LineAlignment calculations....
|
|
|
- int lines=0;
|
|
|
- float layHeight=0;
|
|
|
- float layPrevHeight=0;
|
|
|
- float layWidth=0;
|
|
|
- float drawPosY = y;
|
|
|
- //bool fSkipLastLine = false;
|
|
|
- java.awt.font.TextLayout layout;
|
|
|
- java.awt.geom.Rectangle2D bnds = new java.awt.geom.Rectangle2D.Float();
|
|
|
- while(lineMeasurer.getPosition() < prgEnd) {
|
|
|
- layout = lineMeasurer.nextLayout(formatWidth);
|
|
|
- lines++;
|
|
|
- bnds = bnds.createUnion(layout.getBounds());
|
|
|
- layPrevHeight = layHeight;
|
|
|
- layHeight += layout.getDescent() + layout.getLeading() + layout.getAscent();
|
|
|
- float advance;
|
|
|
- if((format != null) &&
|
|
|
- ((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0))
|
|
|
- advance = layout.getAdvance();
|
|
|
- else
|
|
|
- advance = layout.getVisibleAdvance();
|
|
|
- if(layWidth < advance)
|
|
|
- layWidth = advance;
|
|
|
- if((format != null) && ((format.FormatFlags & StringFormatFlags.NoWrap) != 0))
|
|
|
- break;
|
|
|
- }
|
|
|
- //Overhanging parts of glyphs, and unwrapped text reaching outside
|
|
|
- //the formatting rectangle are allowed to show. By default all text
|
|
|
- //and glyph parts reaching outside the formatting rectangle are clipped.
|
|
|
- if((lines == 1) &&
|
|
|
- (format != null) &&
|
|
|
- ((format.FormatFlags & StringFormatFlags.NoClip) != 0)) {
|
|
|
- formatWidth = layWidth;
|
|
|
- }
|
|
|
-
|
|
|
- //Only entire lines are laid out in the formatting rectangle. By default layout
|
|
|
- //continues until the end of the text, or until no more lines are visible as a
|
|
|
- //result of clipping, whichever comes first. Note that the default settings allow
|
|
|
- //the last line to be partially obscured by a formatting rectangle that is not a
|
|
|
- //whole multiple of the line height. To ensure that only whole lines are seen, specify
|
|
|
- //this value and be careful to provide a formatting rectangle at least as tall as the
|
|
|
- //height of one line.
|
|
|
- if(format != null && ((format.FormatFlags & StringFormatFlags.LineLimit) != 0) &&
|
|
|
- layHeight > hei && layPrevHeight < hei) {
|
|
|
- layHeight = layPrevHeight;
|
|
|
- lines--;
|
|
|
- }
|
|
|
-
|
|
|
- retVal.Height = layHeight;
|
|
|
- retVal.Width = layWidth+size/2.5f;
|
|
|
- if(!fDraw)
|
|
|
- return retVal;
|
|
|
-
|
|
|
- NativeObject.setPaint(brush);
|
|
|
- g.setRenderingHint(awt.RenderingHints.KEY_TEXT_ANTIALIASING, awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
-
|
|
|
- //end measurment
|
|
|
-
|
|
|
- //for draw we should probably update origins
|
|
|
-
|
|
|
- //Vertical...
|
|
|
- if(format != null) {
|
|
|
- StringAlignment align = format.LineAlignment;
|
|
|
- if(align == StringAlignment.Center) {
|
|
|
- drawPosY = y + (float)hei/2 - layHeight/2;
|
|
|
- }
|
|
|
- else if(align == StringAlignment.Far) {
|
|
|
- drawPosY = (float)y + (float)hei - layHeight;
|
|
|
- }
|
|
|
- //in both cases if string is not fit - switch to near
|
|
|
- if(drawPosY < y)
|
|
|
- drawPosY = y;
|
|
|
- }
|
|
|
-
|
|
|
- //Horisontal... on the fly
|
|
|
- lineMeasurer.setPosition(prgStart);
|
|
|
- float drawPosX = x;
|
|
|
- for(int line = 0;line < lines /*lineMeasurer.getPosition() < prgEnd*/;line++, drawPosY += layout.getDescent() + layout.getLeading()) {
|
|
|
- layout = lineMeasurer.nextLayout(formatWidth);
|
|
|
- drawPosX = x + size / (float)5;//???
|
|
|
- drawPosY += layout.getAscent();
|
|
|
- if(format != null) {
|
|
|
- float advance;
|
|
|
- if((format.FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0)
|
|
|
- advance = layout.getAdvance();
|
|
|
- else
|
|
|
- advance = layout.getVisibleAdvance();
|
|
|
-
|
|
|
- if(format.Alignment == StringAlignment.Center) {
|
|
|
- drawPosX = (float)((double)x + ((double)formatWidth)/2 - advance/2);
|
|
|
- }
|
|
|
- else if(format.Alignment == StringAlignment.Far) {
|
|
|
- drawPosX = (float)(drawPosX + formatWidth) - advance;
|
|
|
- }
|
|
|
- if((format.FormatFlags & StringFormatFlags.DirectionVertical ) != 0) {
|
|
|
- java.awt.geom.AffineTransform at1 = java.awt.geom.AffineTransform.getTranslateInstance(
|
|
|
- drawPosX + size / (float)5, (drawPosY - layout.getAscent()) + size / (float)5);
|
|
|
-
|
|
|
- at1.rotate(Math.PI/2);
|
|
|
- awt.Shape sha = textlayout.getOutline(at1);
|
|
|
- geom.AffineTransform t = GetFinalTransform();
|
|
|
- if (!t.isIdentity())
|
|
|
- sha = t.createTransformedShape(sha);
|
|
|
- //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
- g.fill(sha);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if((format.FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0) {
|
|
|
- drawPosX = ((drawPosX + formatWidth) - advance) + (float)9;
|
|
|
- layout.draw(g, drawPosX, drawPosY);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- geom.AffineTransform oldT = null;
|
|
|
- geom.AffineTransform ft = GetFinalTransform();
|
|
|
-
|
|
|
- //Draw current line
|
|
|
- try {
|
|
|
- if (!ft.isIdentity()) {
|
|
|
- oldT = NativeObject.getTransform();
|
|
|
- NativeObject.transform(ft);
|
|
|
- }
|
|
|
- layout.draw(g, drawPosX, drawPosY);
|
|
|
- }
|
|
|
- finally {
|
|
|
- if (oldT != null)
|
|
|
- NativeObject.setTransform(oldT);
|
|
|
- }
|
|
|
- }
|
|
|
- } //not nulls
|
|
|
-
|
|
|
- return retVal;
|
|
|
- }
|
|
|
#endregion
|
|
|
|
|
|
#region Dispose
|