diff --git a/samples/TestApplication/Program.cs b/samples/TestApplication/Program.cs index d44fd7546a..3fcdcd4e80 100644 --- a/samples/TestApplication/Program.cs +++ b/samples/TestApplication/Program.cs @@ -377,20 +377,20 @@ namespace TestApplication Header = "Html", Content = new ScrollViewer() { - Width = 500, + Width = 900, VerticalScrollBarVisibility = ScrollBarVisibility.Visible, Content = new Border { - Height = 1500, + Height = 2500, Child = new HtmlLabel() { Text = htmlText, AutoSize = false, - MaxWidth = 500, - MaxHeight = 900 + MaxWidth = 900, + MaxHeight = 2500 } } diff --git a/src/Perspex.HtmlRenderer/Adapters/FontAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/FontAdapter.cs index 43b726ec8c..1e645cd96c 100644 --- a/src/Perspex.HtmlRenderer/Adapters/FontAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/FontAdapter.cs @@ -59,8 +59,8 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters Name = fontFamily; _size = size; //TODO: Somehow get proper line spacing and underlinePosition - var lineSpacing = 2; - var underlinePosition = 1; + var lineSpacing = 1; + var underlinePosition = 0; _height = 96d / 72d * _size * lineSpacing; _underlineOffset = 96d / 72d * _size * (lineSpacing + underlinePosition); diff --git a/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs index ef0901692d..6b3aacd500 100644 --- a/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/GraphicsAdapter.cs @@ -11,6 +11,7 @@ // "The Art of War" using System; +using System.Collections.Generic; using System.Globalization; using Perspex; using Perspex.Media; @@ -41,6 +42,9 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters #endregion + private Stack _clipStack = new Stack(); + + /// /// Init. /// @@ -66,22 +70,25 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters _releaseGraphics = false; } + + public override void PopClip() { - /* - _g.Pop(); - _clipStack.Pop(); - */ + _clipStack.Pop()?.Dispose(); } public override void PushClip(RRect rect) { + _clipStack.Push(_g.PushClip(Util.Convert(rect))); //_clipStack.Push(rect); //_g.PushClip(new RectangleGeometry(Utils.Convert(rect))); } public override void PushClipExclude(RRect rect) { + _clipStack.Push(null); + + //TODO: Implement exclude rect, see #128 //var geometry = new CombinedGeometry(); //geometry.Geometry1 = new RectangleGeometry(Utils.Convert(_clipStack.Peek())); //geometry.Geometry2 = new RectangleGeometry(Utils.Convert(rect)); @@ -125,46 +132,6 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters var text = GetText(str, font); text.Constraint = Util.Convert(size); _g.DrawText(new SolidColorBrush(Util.Convert(color)), Util.Convert(point), text); - - //var colorConv = ((BrushAdapter)_adapter.GetSolidBrush(color)).Brush; - - //bool glyphRendered = false; - //GlyphTypeface glyphTypeface = ((FontAdapter)font).GlyphTypeface; - //if (glyphTypeface != null) - //{ - // double width = 0; - // ushort[] glyphs = new ushort[str.Length]; - // double[] widths = new double[str.Length]; - - // int i = 0; - // for (; i < str.Length; i++) - // { - // ushort glyph; - // if (!glyphTypeface.CharacterToGlyphMap.TryGetValue(str[i], out glyph)) - // break; - - // glyphs[i] = glyph; - // width += glyphTypeface.AdvanceWidths[glyph]; - // widths[i] = 96d / 72d * font.Size * glyphTypeface.AdvanceWidths[glyph]; - // } - - // if (i >= str.Length) - // { - // point.Y += glyphTypeface.Baseline * font.Size * 96d / 72d; - // point.X += rtl ? 96d / 72d * font.Size * width : 0; - - // glyphRendered = true; - // var glyphRun = new GlyphRun(glyphTypeface, rtl ? 1 : 0, false, 96d / 72d * font.Size, glyphs, Utils.ConvertRound(point), widths, null, null, null, null, null, null); - // _g.DrawGlyphRun(colorConv, glyphRun); - // } - //} - - //if (!glyphRendered) - //{ - // var formattedText = new FormattedText(str, CultureInfo.CurrentCulture, rtl ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, ((FontAdapter)font).Font, 96d / 72d * font.Size, colorConv); - // point.X += rtl ? formattedText.Width : 0; - // _g.DrawText(formattedText, Utils.ConvertRound(point)); - //} } public override RBrush GetTextureBrush(RImage image, RRect dstRect, RPoint translateTransformLocation) @@ -266,6 +233,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters context.BeginFigure(Util.Convert(points[0]), true); for (int i = 1; i < points.Length; i++) context.LineTo(Util.Convert(points[i])); + context.EndFigure(false); } _g.DrawGeometry(((BrushAdapter)brush).Brush, null, g); diff --git a/src/Perspex.HtmlRenderer/Adapters/GraphicsPathAdapter.cs b/src/Perspex.HtmlRenderer/Adapters/GraphicsPathAdapter.cs index 80797429de..5ccfa7140c 100644 --- a/src/Perspex.HtmlRenderer/Adapters/GraphicsPathAdapter.cs +++ b/src/Perspex.HtmlRenderer/Adapters/GraphicsPathAdapter.cs @@ -57,6 +57,7 @@ namespace TheArtOfDev.HtmlRenderer.Perspex.Adapters public StreamGeometry GetClosedGeometry() { _geometryContext.EndFigure(true); + _geometryContext.Dispose(); return _geometry; }