Browse Source

HTML: Seems to be rendering more like reference implementation

Nikita Tsukanov 10 years ago
parent
commit
34dff255f5

+ 4 - 4
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
 
                                 }
                         }

+ 2 - 2
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);

+ 12 - 44
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<IDisposable> _clipStack = new Stack<IDisposable>();
+
+
         /// <summary>
         /// Init.
         /// </summary>
@@ -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);

+ 1 - 0
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;
         }