Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog4
-rwxr-xr-xmcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.jvm.cs38
-rwxr-xr-xmcs/class/System.Drawing/System.Drawing.Text/LineLayout.jvm.cs187
-rwxr-xr-xmcs/class/System.Drawing/System.Drawing.Text/TextLineIterator.jvm.cs242
-rw-r--r--mcs/class/System.Drawing/System.Drawing.Text/changelog4
-rw-r--r--mcs/class/System.Drawing/System.Drawing.vmwcsproj2
-rw-r--r--mcs/class/System.Drawing/System.Drawing/ChangeLog5
-rwxr-xr-xmcs/class/System.Drawing/System.Drawing/Graphics.jvm.cs302
-rw-r--r--mcs/class/System.Drawing/System.Drawing/StringFormat.jvm.cs58
9 files changed, 775 insertions, 67 deletions
diff --git a/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog b/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog
index 96177f685d9..97eb9710369 100644
--- a/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog
+++ b/mcs/class/System.Drawing/System.Drawing.Drawing2D/ChangeLog
@@ -1,5 +1,9 @@
2005-11-13 Konstantin Triger <kostat@mainsoft.com>
+ * GraphicsPath.jvm.cs: AddString support.
+
+2005-11-13 Konstantin Triger <kostat@mainsoft.com>
+
* ExtendedGeneralPath.jvm.cs: restore quadTo as curveTo affects quality
2005-11-13 Konstantin Triger <kostat@mainsoft.com>
diff --git a/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.jvm.cs b/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.jvm.cs
index f0626bdba9b..76363d614d2 100755
--- a/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.jvm.cs
+++ b/mcs/class/System.Drawing/System.Drawing.Drawing2D/GraphicsPath.jvm.cs
@@ -28,6 +28,7 @@
//
using System;
using System.Drawing;
+using System.Drawing.Text;
using System.Collections;
using java.awt.geom;
using java.awt;
@@ -775,28 +776,49 @@ namespace System.Drawing.Drawing2D
#endregion
#region AddString
- [MonoTODO]
public void AddString (string s, FontFamily family, int style, float emSize, Point origin, StringFormat format)
{
- throw new NotImplementedException ();
+ AddString(s, new Font(family, emSize, (FontStyle)style, GraphicsUnit.World), origin.X, origin.Y, float.PositiveInfinity, float.PositiveInfinity,
+ format);
}
- [MonoTODO]
public void AddString (string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format)
{
- throw new NotImplementedException ();
+ AddString(s, new Font(family, emSize, (FontStyle)style, GraphicsUnit.World), origin.X, origin.Y, float.PositiveInfinity, float.PositiveInfinity,
+ format);
}
- [MonoTODO]
public void AddString (string s, FontFamily family, int style, float emSize, Rectangle layoutRect, StringFormat format)
{
- throw new NotImplementedException ();
+ AddString(s, new Font(family, emSize, (FontStyle)style, GraphicsUnit.World),
+ layoutRect.X, layoutRect.Y, layoutRect.Width, layoutRect.Height,
+ format);
}
- [MonoTODO]
public void AddString (string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format)
{
- throw new NotImplementedException ();
+ AddString(s, new Font(family, emSize, (FontStyle)style, GraphicsUnit.World),
+ layoutRect.X, layoutRect.Y, layoutRect.Width, layoutRect.Height,
+ format);
+ }
+
+ 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);
}
#endregion
diff --git a/mcs/class/System.Drawing/System.Drawing.Text/LineLayout.jvm.cs b/mcs/class/System.Drawing/System.Drawing.Text/LineLayout.jvm.cs
new file mode 100755
index 00000000000..4771f028751
--- /dev/null
+++ b/mcs/class/System.Drawing/System.Drawing.Text/LineLayout.jvm.cs
@@ -0,0 +1,187 @@
+//
+// System.Drawing.Test.LineLayout.jvm.cs
+//
+// Author:
+// Konstantin Triger <kostat@mainsoft.com>
+//
+// Copyright (C) 2005 Mainsoft Corporation, (http://www.mainsoft.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Drawing.Drawing2D;
+
+using font = java.awt.font;
+using text = java.text;
+using awt = java.awt;
+using geom = java.awt.geom;
+
+namespace System.Drawing.Text {
+
+ internal sealed class LineLayout {
+
+ #region Fields
+
+ readonly font.TextLayout _layout;
+
+ readonly float _accumulatedHeight;
+ readonly TextLineIterator _lineIter;
+
+ #endregion
+
+ #region ctor
+
+ internal LineLayout(font.TextLayout layout,
+ TextLineIterator lineIter,
+ float accumulatedHeight) {
+
+ _layout = layout;
+ _lineIter = lineIter;
+ _accumulatedHeight = accumulatedHeight;
+ }
+
+ #endregion
+
+ #region Properties
+
+ internal float AccumulatedHeight {
+ get { return _accumulatedHeight; }
+ }
+
+ internal float MeasureWidth {
+ get {
+ return Width + (_lineIter.Margin*2);
+ }
+ }
+
+ internal int CharacterCount {
+ get { return _layout.getCharacterCount(); }
+ }
+
+ internal float Ascent {
+ get { return _layout.getAscent(); }
+ }
+
+ internal float Descent {
+ get { return _layout.getDescent(); }
+ }
+
+ public float Leading {
+ get { return _layout.getLeading(); }
+ }
+
+ internal float NativeY {
+ get {
+ if (_lineIter.Format.IsVertical) {
+ float height = _lineIter.Height;
+ if (float.IsPositiveInfinity(height))
+ height = 0;
+ switch (_lineIter.Format.Alignment) {
+ case StringAlignment.Center:
+ return (height - Width) / 2;
+ case StringAlignment.Far:
+ return height - _layout.getVisibleAdvance() - _lineIter.Margin;
+ default:
+ return _lineIter.Margin;
+ }
+ }
+ else
+ return AccumulatedHeight + Ascent;
+ }
+ }
+
+ internal float NativeX {
+ get {
+ float width = _lineIter.Width;
+ if (float.IsPositiveInfinity(width))
+ width = 0;
+ if (_lineIter.Format.IsVertical)
+ return (_lineIter.Format.IsRightToLeft) ?
+ width - AccumulatedHeight - Ascent :
+ AccumulatedHeight + Leading + Descent;
+ else {
+ float xOffset;
+ switch ( _lineIter.Format.Alignment) {
+ case StringAlignment.Center:
+ xOffset = (width - Width) / 2;
+ break;
+ case StringAlignment.Far:
+ if (_lineIter.Format.IsRightToLeft)
+ xOffset = _lineIter.Margin;
+ else
+ xOffset = width - _layout.getVisibleAdvance() - _lineIter.Margin;
+ break;
+ default:
+ if (_lineIter.Format.IsRightToLeft)
+ xOffset = width - _layout.getVisibleAdvance() - _lineIter.Margin;
+ else
+ xOffset = _lineIter.Margin;
+ break;
+ }
+
+ return xOffset;
+ }
+ }
+ }
+
+ internal float Height {
+ get {
+ return Ascent + Descent + Leading;
+ }
+ }
+
+ internal float Width {
+ get {
+ if (_lineIter.Format.MeasureTrailingSpaces)
+ if (!(_lineIter.Format.IsRightToLeft ^
+ (_lineIter.Format.Alignment == StringAlignment.Far)))
+ return _layout.getAdvance();
+
+ return _layout.getVisibleAdvance();
+ }
+ }
+
+ #endregion
+
+ #region Methods
+
+ internal void Draw(awt.Graphics2D g2d, float x, float y) {
+ if (_lineIter.Format.IsVertical)
+ _layout.draw(g2d, y + NativeY, -(x + NativeX) );
+ else
+ _layout.draw(g2d, x + NativeX, y + NativeY );
+ }
+
+ internal awt.Shape GetOutline(float x, float y) {
+ geom.AffineTransform t = (geom.AffineTransform)_lineIter.Transform.clone();
+
+ if (_lineIter.Format.IsVertical)
+ t.translate(y + NativeY, -(x + NativeX));
+ else
+ t.translate(x + NativeX, y + NativeY);
+
+ return _layout.getOutline(t);
+ }
+
+ #endregion
+ }
+
+} \ No newline at end of file
diff --git a/mcs/class/System.Drawing/System.Drawing.Text/TextLineIterator.jvm.cs b/mcs/class/System.Drawing/System.Drawing.Text/TextLineIterator.jvm.cs
new file mode 100755
index 00000000000..59bdf4cccbd
--- /dev/null
+++ b/mcs/class/System.Drawing/System.Drawing.Text/TextLineIterator.jvm.cs
@@ -0,0 +1,242 @@
+//
+// System.Drawing.Test.TextLineIterator.jvm.cs
+//
+// Author:
+// Konstantin Triger <kostat@mainsoft.com>
+//
+// Copyright (C) 2005 Mainsoft Corporation, (http://www.mainsoft.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Drawing.Drawing2D;
+
+using font = java.awt.font;
+using text = java.text;
+using awt = java.awt;
+using geom = java.awt.geom;
+
+namespace System.Drawing.Text {
+ internal sealed class TextLineIterator {
+
+ #region Fields
+
+ readonly float _width;
+ readonly float _height;
+ readonly StringFormat _format;
+ readonly font.FontRenderContext _frc;
+ readonly string _s;
+ readonly Font _font;
+ readonly float _margin;
+
+ static readonly string NewLine;
+
+ static readonly geom.AffineTransform Rotate90Transform =
+ geom.AffineTransform.getRotateInstance(Math.PI/2);
+
+ font.TextMeasurer _measurer;
+ int _charsConsumed = 0;
+ int _currentPos = 0;
+ int _currentRun = 0;
+ float _accumulatedHeight = 0;
+
+ #endregion
+
+ #region ctors
+
+ static TextLineIterator() {
+ string newLine = Environment.NewLine;
+ if (newLine == null || newLine.Length == 0 || newLine[newLine.Length - 1] == '\n')
+ newLine = "\n";
+
+ NewLine = newLine;
+ }
+
+ internal TextLineIterator(string s, Font font, font.FontRenderContext frc, StringFormat format, float width, float height) {
+ _format = (format != null) ? format : new StringFormat();
+ _font = font;
+ _s = s;
+ _frc = frc;
+ FontFamily ff = font.FontFamily;
+ _margin = font.Size*ff.GetDrawMargin(font.Style)/ff.GetEmHeight(font.Style);
+
+ _width = width;
+ _height = height;
+ }
+
+ #endregion
+
+ #region Properties
+
+ float WrapWidth {
+ get { return (_format.IsVertical ? Height : Width) - (Margin * 2); }
+ }
+
+ internal float WrapHeight {
+ get { return (_format.IsVertical ? Width : Height); }
+ }
+
+ internal float Width {
+ get { return _width; }
+ }
+
+ internal float Height {
+ get { return _height; }
+ }
+
+ internal StringFormat Format {
+ get { return _format; }
+ }
+
+ internal float Margin {
+ get { return _margin; }
+ }
+
+ internal int CharsConsumed {
+ get { return _charsConsumed; }
+ }
+
+ internal int CurrentRun {
+ get { return _currentRun; }
+ }
+
+ internal int CurrentPosition {
+ get { return _currentPos; }
+ }
+
+ internal float AccumulatedHeight {
+ get { return _accumulatedHeight; }
+ }
+
+ internal float GetAdvanceBetween(int start, int limit) {
+ return _measurer.getAdvanceBetween(start, limit);
+ }
+
+ internal geom.AffineTransform Transform {
+ get { return Format.IsVertical ? Rotate90Transform : Matrix.IdentityTransform.NativeObject; }
+ }
+
+ #endregion
+
+ #region Methods
+
+ LineLayout NextTextLayoutFromMeasurer() {
+ if (_accumulatedHeight >= WrapHeight) {
+ _charsConsumed += _currentPos;
+ return null;
+ }
+
+ int limit = _measurer.getLineBreakIndex(_currentPos, WrapWidth);
+
+ int wordBreak = limit;
+ if (wordBreak < _currentRun) {
+ while (wordBreak >= _currentPos && char.IsLetterOrDigit(_s, _charsConsumed + wordBreak))
+ wordBreak--;
+
+ if (wordBreak > _currentPos)
+ limit = wordBreak + 1;
+ }
+ font.TextLayout layout = _measurer.getLayout(_currentPos, limit);
+
+ LineLayout lineLayout = new LineLayout(
+ layout,
+ this,
+ _accumulatedHeight);
+
+ float lineHeight = lineLayout.Ascent + lineLayout.Descent;
+
+ if (Format.LineLimit && (_accumulatedHeight + lineHeight > WrapHeight)) {
+ _charsConsumed += _currentPos;
+ return null;
+ }
+
+ _accumulatedHeight += lineHeight + lineLayout.Leading;
+
+ _currentPos = limit;
+
+ while (_currentPos < _currentRun) {
+ if (char.IsWhiteSpace(_s, _charsConsumed + _currentPos))
+ _currentPos++;
+ else
+ break;
+ }
+ return lineLayout;
+ }
+
+ internal LineLayout NextLine() {
+ if (_currentPos < _currentRun && !Format.NoWrap)
+ return NextTextLayoutFromMeasurer();
+
+ _charsConsumed += _currentRun;
+ if (_charsConsumed >= _s.Length)
+ return null;
+
+ string s;
+ int lineBreakIndex = _s.IndexOf(NewLine, _charsConsumed);
+ if (lineBreakIndex >= 0) {
+ s = _s.Substring(_charsConsumed, lineBreakIndex - _charsConsumed + NewLine.Length);
+ }
+ else
+ s = _s.Substring(_charsConsumed);
+
+ _currentRun = s.Length;
+ _currentPos = 0;
+
+ text.AttributedString aS = new text.AttributedString(s);
+
+ // TODO: add more attribs according to StringFormat
+ aS.addAttribute(font.TextAttribute.FONT, _font.NativeObject);
+ if((_font.Style & FontStyle.Underline) != FontStyle.Regular)
+ aS.addAttribute(font.TextAttribute.UNDERLINE, font.TextAttribute.UNDERLINE_ON);
+ if((_font.Style & FontStyle.Strikeout) != FontStyle.Regular)
+ aS.addAttribute(font.TextAttribute.STRIKETHROUGH, font.TextAttribute.STRIKETHROUGH_ON);
+
+ text.AttributedCharacterIterator charIter = aS.getIterator();
+
+ _measurer = new font.TextMeasurer(charIter, _frc);
+ return NextTextLayoutFromMeasurer();
+ }
+
+ internal geom.AffineTransform CalcLineAlignmentTransform() {
+ if (Format.LineAlignment == StringAlignment.Near)
+ return null;
+ float height = WrapHeight;
+ if (float.IsPositiveInfinity(height))
+ height = 0;
+
+ float shift = height - AccumulatedHeight;
+ if (height > 0 && shift <= 0)
+ return null;
+
+ if (Format.LineAlignment == StringAlignment.Center)
+ shift /= 2;
+ else
+ if (Format.IsVertical && Format.IsRightToLeft)
+ return null;
+
+ return Format.IsVertical ?
+ geom.AffineTransform.getTranslateInstance(shift, 0) :
+ geom.AffineTransform.getTranslateInstance(0, shift);
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/mcs/class/System.Drawing/System.Drawing.Text/changelog b/mcs/class/System.Drawing/System.Drawing.Text/changelog
index c1ce97d747e..54aa038afaa 100644
--- a/mcs/class/System.Drawing/System.Drawing.Text/changelog
+++ b/mcs/class/System.Drawing/System.Drawing.Text/changelog
@@ -1,3 +1,7 @@
+2005-11-13 Konstantin Triger <kostat@mainsoft.com>
+
+ * Added LineLayout.jvm.cs, TextLineIterator.jvm.cs for text support
+
2005-11-10 Vladimir Krasnov <vladimirk@mainsoft.com>
* FontCollection.jvm.cs: refactoring, added GetInitialFont()
diff --git a/mcs/class/System.Drawing/System.Drawing.vmwcsproj b/mcs/class/System.Drawing/System.Drawing.vmwcsproj
index 98500a73218..babbfc09724 100644
--- a/mcs/class/System.Drawing/System.Drawing.vmwcsproj
+++ b/mcs/class/System.Drawing/System.Drawing.vmwcsproj
@@ -150,7 +150,9 @@
<File RelPath="System.Drawing.Text\GenericFontFamilies.cs" SubType="Code" BuildAction="Compile"/>
<File RelPath="System.Drawing.Text\HotkeyPrefix.cs" SubType="Code" BuildAction="Compile"/>
<File RelPath="System.Drawing.Text\InstalledFontCollection.jvm.cs" SubType="Code" BuildAction="Compile"/>
+ <File RelPath="System.Drawing.Text\LineLayout.jvm.cs" SubType="Code" BuildAction="Compile"/>
<File RelPath="System.Drawing.Text\PrivateFontCollection.jvm.cs" SubType="Code" BuildAction="Compile"/>
+ <File RelPath="System.Drawing.Text\TextLineIterator.jvm.cs" SubType="Code" BuildAction="Compile"/>
<File RelPath="System.Drawing.Text\TextRenderingHint.cs" SubType="Code" BuildAction="Compile"/>
</Include>
</Files>
diff --git a/mcs/class/System.Drawing/System.Drawing/ChangeLog b/mcs/class/System.Drawing/System.Drawing/ChangeLog
index 1318bfde438..13e51406190 100644
--- a/mcs/class/System.Drawing/System.Drawing/ChangeLog
+++ b/mcs/class/System.Drawing/System.Drawing/ChangeLog
@@ -1,5 +1,10 @@
2005-11-13 Konstantin Triger <kostat@mainsoft.com>
+ * StringFormat.jvm.cs, Graphics.jvm.cs: DrawString,
+ MeasureString support
+
+2005-11-13 Konstantin Triger <kostat@mainsoft.com>
+
* FontFamily.jvm.cs: correctly initialize fontcollection
2005-11-13 Konstantin Triger <kostat@mainsoft.com>
diff --git a/mcs/class/System.Drawing/System.Drawing/Graphics.jvm.cs b/mcs/class/System.Drawing/System.Drawing/Graphics.jvm.cs
index 5354dba1d50..99213719c9d 100755
--- a/mcs/class/System.Drawing/System.Drawing/Graphics.jvm.cs
+++ b/mcs/class/System.Drawing/System.Drawing/Graphics.jvm.cs
@@ -167,6 +167,7 @@ namespace System.Drawing {
readonly awt.Graphics2D _nativeObject;
PixelOffsetMode _pixelOffsetMode = PixelOffsetMode.Default;
int _textContrast = 4;
+ TextRenderingHint _textRenderingHint;
readonly Image _image;
readonly Matrix _transform;
@@ -232,6 +233,7 @@ namespace System.Drawing {
NativeObject.setRenderingHint(awt.RenderingHints.KEY_COLOR_RENDERING, awt.RenderingHints.VALUE_COLOR_RENDER_QUALITY);
InterpolationMode = InterpolationMode.Bilinear;
+ TextRenderingHint = TextRenderingHint.SystemDefault;
_windowRect = new awt.Rectangle(_image.Width, _image.Height);
_clip = new Region();
@@ -1195,46 +1197,96 @@ namespace System.Drawing {
#region DrawString
public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle) {
- MeasureDraw(s,font,brush,layoutRectangle,null,true);
+ DrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, null);
}
public void DrawString (string s, Font font, Brush brush, PointF point) {
- MeasureDraw(s,font,brush,new RectangleF(point.X,point.Y,99999f,99999f),null,true);
+ DrawString(s, font, brush, point.X, point.Y, float.PositiveInfinity, float.PositiveInfinity, null);
}
public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format) {
- MeasureDraw(s,font,brush,new RectangleF(point.X,point.Y,99999f,99999f),format,true);
+ DrawString(s, font, brush, point.X, point.Y, float.PositiveInfinity, float.PositiveInfinity, format);
}
public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) {
- MeasureDraw(s,font,brush,layoutRectangle,format,true);
+ DrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, format);
}
-
-#if false
- public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
- {
- java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
- //set
- java.awt.Paint oldpaint = g.getPaint();
- g.setPaint(brush.NativeObject);
- java.awt.Font oldfont = g.getFont();
- g.setFont(font.NativeObject);
- java.awt.Shape oldb = g.getClip();
- g.setClip(new java.awt.geom.Rectangle2D.Float(layoutRectangle.X,layoutRectangle.Y,layoutRectangle.Width,layoutRectangle.Height));
- //draw
- g.drawString(s,layoutRectangle.X,layoutRectangle.Y+layoutRectangle.Height);
- //restore
- g.setPaint(oldpaint);
- g.setClip(oldb);
- g.setFont(oldfont);
- }
-#endif
+
public void DrawString (string s, Font font, Brush brush, float x, float y) {
- MeasureDraw(s,font,brush,new RectangleF(x,y,99999f,99999f),null,true);
+ DrawString(s, font, brush, x, y, float.PositiveInfinity, float.PositiveInfinity, null);
}
public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format) {
- MeasureDraw(s,font,brush,new RectangleF(x,y,99999f,99999f),format,true);
+ DrawString(s, font, brush, x, y, float.PositiveInfinity, float.PositiveInfinity, format);
+ }
+
+ 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();
+ NativeObject.transform(GetFinalTransform());
+ 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, y);
+ }
+ }
+ finally {
+ if (!noclip)
+ NativeObject.setClip(oldClip);
+ }
+ }
+ finally {
+ NativeObject.setTransform(oldT);
+ }
+ }
+ finally {
+ NativeObject.setPaint(oldP);
+ }
}
#endregion
@@ -1838,47 +1890,178 @@ namespace System.Drawing {
}
#endregion
- #region MeasureCharacterRanges [TODO]
+ #region MeasureCharacterRanges
public Region [] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat) {
- throw new NotImplementedException();
+ 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;
}
#endregion
- #region MeasureString [1 method still TODO]
+ #region MeasureString
public SizeF MeasureString (string text, Font font) {
- return MeasureDraw(text,font,null,new RectangleF(0,0,99999f,99999f),null,false);
+ return MeasureString(text, font, null, float.PositiveInfinity, float.PositiveInfinity, null);
}
public SizeF MeasureString (string text, Font font, SizeF layoutArea) {
- return MeasureDraw(text,font,null,new RectangleF(0,0,layoutArea.Width,layoutArea.Height),null,false);
+ return MeasureString(text, font, layoutArea, null);
}
public SizeF MeasureString (string text, Font font, int width) {
- return MeasureDraw(text,font,null,new RectangleF(0,0,(float)width,99999f),null,false);
+ return MeasureString(text, font, width, null);
}
public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat format) {
- return MeasureDraw(text,font,null,new RectangleF(0,0,layoutArea.Width,layoutArea.Height),format,false);
+ return MeasureString(text, font, format, layoutArea.Width, layoutArea.Height, null);
}
public SizeF MeasureString (string text, Font font, int width, StringFormat format) {
- return MeasureDraw(text,font,null,new RectangleF(0,0,(float)width,99999f),format,false);
+ return MeasureString(text, font, format, width, float.PositiveInfinity, null);
}
public SizeF MeasureString (string text, Font font, PointF origin, StringFormat format) {
- //TBD: MeasureDraw still not dealing with clipping region of dc
- return MeasureDraw(text,font,null,new RectangleF(origin.X,origin.Y,99999f,99999f),format,false);
+ return MeasureString(text, font, format, float.PositiveInfinity, float.PositiveInfinity, null);
+ }
+
+ 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, mheight);
}
public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat, out int charactersFitted, out int linesFilled) {
- //TBD: charcount
- throw new NotImplementedException();
+ linesFilled = 0;
+ charactersFitted = 0;
+
+ int[] statistics = new int[2];
+ SizeF sz = MeasureString(text, font, stringFormat, layoutArea.Width, layoutArea.Height, statistics);
+ linesFilled = statistics[0];
+ charactersFitted = statistics[1];
+ return sz;
}
#endregion
@@ -2401,30 +2584,49 @@ namespace System.Drawing {
public TextRenderingHint TextRenderingHint {
get {
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- if(hints.containsKey(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING)) {
- if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
- java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
- return TextRenderingHint.AntiAlias;
- if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
- java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
- return TextRenderingHint.SingleBitPerPixel;
- }
- return TextRenderingHint.SystemDefault;
+ return _textRenderingHint;
+// awt.RenderingHints hints = NativeObject.getRenderingHints();
+// if(hints.containsKey(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING)) {
+// if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
+// java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
+// return TextRenderingHint.AntiAlias;
+// if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
+// java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
+// return TextRenderingHint.SingleBitPerPixel;
+// }
+// //return TextRenderingHint.SystemDefault;
+// return TextRenderingHint.SingleBitPerPixelGridFit;
}
set {
- // TODO implement
+ _textRenderingHint = value;
awt.RenderingHints hints = NativeObject.getRenderingHints();
switch (value) {
case TextRenderingHint.AntiAlias:
case TextRenderingHint.AntiAliasGridFit:
case TextRenderingHint.ClearTypeGridFit:
- case TextRenderingHint.SingleBitPerPixel:
+// case TextRenderingHint.SystemDefault:
+ hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
+ awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ break;
+
case TextRenderingHint.SingleBitPerPixelGridFit:
+ hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
+ awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
+ break;
+
+ case TextRenderingHint.SingleBitPerPixel:
+ hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
+ awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
+ break;
+
case TextRenderingHint.SystemDefault:
+ hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
+ awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
break;
}
+
+ NativeObject.setRenderingHints(hints);
}
}
diff --git a/mcs/class/System.Drawing/System.Drawing/StringFormat.jvm.cs b/mcs/class/System.Drawing/System.Drawing/StringFormat.jvm.cs
index 130ff2fdec2..c11d4bafa15 100644
--- a/mcs/class/System.Drawing/System.Drawing/StringFormat.jvm.cs
+++ b/mcs/class/System.Drawing/System.Drawing/StringFormat.jvm.cs
@@ -181,22 +181,62 @@ namespace System.Drawing {
#endregion
- #region public methods
-
- public void SetMeasurableCharacterRanges (CharacterRange [] range) {
- _charRanges = (CharacterRange [])range.Clone();
+ #region internal accessors
+ internal bool NoWrap {
+ get {
+ return (FormatFlags & StringFormatFlags.NoWrap) != 0;
+ }
+ }
+
+ internal bool IsVertical {
+ get {
+ return (FormatFlags & StringFormatFlags.DirectionVertical) != 0;
+ }
+ }
+
+ internal bool MeasureTrailingSpaces {
+ get {
+ return (FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0;
+ }
+ }
+
+ internal bool LineLimit {
+ get {
+ return (FormatFlags & StringFormatFlags.LineLimit) != 0;
+ }
+ }
+
+ internal bool NoClip {
+ get {
+ return (FormatFlags & StringFormatFlags.NoClip) != 0;
+ }
}
- internal CharacterRange [] GetCharRanges {
+ internal bool IsRightToLeft {
+ get {
+ return (FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0;
+ }
+ }
+
+ internal CharacterRange [] CharRanges {
get {
return _charRanges;
}
}
+ #endregion
+
+ #region public methods
+
+ public void SetMeasurableCharacterRanges (CharacterRange [] range) {
+ _charRanges = range != null ? (CharacterRange [])range.Clone() : null;
+ }
public object Clone() {
StringFormat copy = (StringFormat)MemberwiseClone();
- copy._charRanges = (CharacterRange [])_charRanges.Clone();
- copy._tabStops = (float[])_tabStops.Clone();
+ if (_charRanges != null)
+ copy._charRanges = (CharacterRange [])_charRanges.Clone();
+ if (_tabStops != null)
+ copy._tabStops = (float[])_tabStops.Clone();
return copy;
}
@@ -206,7 +246,7 @@ namespace System.Drawing {
public void SetTabStops(float firstTabOffset, float[] tabStops) {
_firstTabOffset = firstTabOffset;
- _tabStops = (float[])tabStops.Clone();
+ _tabStops = tabStops != null ? (float[])tabStops.Clone() : null;
}
public void SetDigitSubstitution(int language, StringDigitSubstitute substitute) {
@@ -216,7 +256,7 @@ namespace System.Drawing {
public float[] GetTabStops(out float firstTabOffset) {
firstTabOffset = _firstTabOffset;
- return (float[])_tabStops.Clone();
+ return _tabStops != null ? (float[])_tabStops.Clone() : null;
}
#endregion