Exemplo n.º 1
0
        public void DrawGlyphRun(Brush foreground, GlyphRun glyphRun)
        {
            if (foreground == null)
            {
                return;
            }

            AssertState(DeviceState.PageStarted, DeviceState.NoChange);

            GlyphPrimitive g = new GlyphPrimitive();

            bool needBounds = false;

            if (foreground != null && !(foreground is SolidColorBrush))
            {
                needBounds = true;
            }

            g.GlyphRun    = glyphRun;
            g.Brush       = BrushProxy.CreateBrush(foreground, g.GetRectBounds(needBounds));
            g.Clip        = _clip;
            g.Opacity     = _opacity;
            g.OpacityMask = _opacityMask;

            // Optimization: Unfold primitive DrawingBrush when possible to avoid rasterizing it.
            Primitive primitive = g.UnfoldDrawingBrush();

            if (primitive != null)
            {
                _root.Children.Add(primitive);
            }
        }
Exemplo n.º 2
0
        bool IProxyDrawingContext.DrawGlyphs(GlyphRun glyphrun, Geometry clip, Matrix trans, BrushProxy foreground)
        {
            bool empty;

            clip = Utility.Intersect(_clip, Utility.TransformGeometry(clip, _transform), Matrix.Identity, out empty);

            if (empty)
            {
                return(true);
            }

            GlyphPrimitive gp = new GlyphPrimitive();

            gp.GlyphRun  = glyphrun;
            gp.Clip      = clip;
            gp.Transform = trans * _transform;
            gp.Brush     = foreground;

            gp.PushOpacity(_opacity, _opacityMask);
            _flattener.AddPrimitive(gp);

            return(true);
        }
Exemplo n.º 3
0
        static internal void PrintPrimitive(PrimitiveInfo info, int index, bool verbose)
        {
            if (index < 0)
            {
                Console.WriteLine();

                Console.WriteLine(" No      Type           Und Ovr TrO           Bounding Box                   Clipping");

                if (verbose)
                {
                    Console.Write("                     Transform");
                }

                Console.WriteLine();
                return;
            }

            Primitive p = info.primitive;

            string typ = p.GetType().ToString();

            typ = typ.Substring(typ.LastIndexOf('.') + 1);

            Console.Write(LeftPad(index, 4) + LeftPad(typ, 18) + ":");

            List <int> extra = null;

            if (p.IsOpaque)
            {
                Console.Write(' ');
            }
            else
            {
                Console.Write('@');
            }

            if (info.underlay == null)
            {
                Console.Write("   ");
            }
            else
            {
                extra = info.underlay;

                Console.Write(LeftPad(info.underlay.Count, 3));
            }

            if (info.overlap != null)
            {
                Console.Write(' ' + LeftPad(info.overlap.Count, 3));

                if (info.overlapHasTransparency != 0)
                {
                    Console.Write('$');
                    Console.Write(LeftPad(info.overlapHasTransparency, 3));
                }
                else
                {
                    Console.Write("    ");
                }

                Console.Write(' ');
            }
            else
            {
                Console.Write("         ");
            }

            Console.Write(LeftPad(info.bounds, 0));

            Geometry clip = p.Clip;

            if (clip != null)
            {
                Console.Write(LeftPad(clip.Bounds, 0));
            }

            if (verbose)
            {
                Matrix m = p.Transform;

                Console.Write(" {");
                Console.Write(LeftPad(m.M11, 3) + ' ');
                Console.Write(LeftPad(m.M12, 3) + ' ');
                Console.Write(LeftPad(m.M21, 3) + ' ');
                Console.Write(LeftPad(m.M22, 3) + ' ');
                Console.Write(LeftPad(m.OffsetX, 6) + ' ');
                Console.Write(LeftPad(m.OffsetY, 6));
                Console.Write("} ");
            }

            if (verbose)
            {
                GlyphPrimitive gp = p as GlyphPrimitive;

                if (gp != null)
                {
                    IList <char> chars = gp.GlyphRun.Characters;

                    Console.Write(" \"");

                    for (int i = 0; i < chars.Count; i++)
                    {
                        Console.Write(chars[i]);
                    }

                    Console.Write('"');
                }
            }

            if (verbose)
            {
                GeometryPrimitive gp = p as GeometryPrimitive;

                if ((gp != null) && (gp.Brush != null) && (gp.Pen == null))
                {
                    Brush b = gp.Brush.Brush;

                    if (b != null)
                    {
                        SolidColorBrush sb = b as SolidColorBrush;

                        if (sb != null)
                        {
                            Console.Write(" SolidColorBrush({0})", sb.Color);
                        }
                    }
                }
            }

            if (extra != null)
            {
                Console.Write(' ');
                Console.Write(LeftPad(extra, 0));
            }

            Console.WriteLine();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Resolve overlapping for a single primitive
        /// </summary>
        /// <param name="primitive"></param>
        /// <param name="overlapping"></param>
        /// <param name="overlapHasTransparency"></param>
        /// <param name="disjoint"></param>
        /// <param name="desp"></param>
        private void AlphaRender(Primitive primitive, List <int> overlapping, int overlapHasTransparency, bool disjoint, string desp)
        {
            if (primitive == null)
            {
                return;
            }

            // Skip alpha flattening when there are too many layer of transparency
            if (overlapHasTransparency > Configuration.MaximumTransparencyLayer)
            {
                overlapping = null;
            }

            PrimitiveRenderer ri = new PrimitiveRenderer();

            ri.Clip        = primitive.Clip;
            ri.Brush       = null;
            ri.Pen         = null;
            ri.Overlapping = overlapping;
            ri.Commands    = _dl.Commands;
            ri.DC          = _dc;
            ri.Disjoint    = disjoint;

            GeometryPrimitive p = primitive as GeometryPrimitive;

            if (p != null)
            {
                ri.Brush = p.Brush;
                ri.Pen   = p.Pen;

                bool done = false;

                Geometry g = p.Geometry;

                GlyphPrimitive gp = p as GlyphPrimitive;

                if (gp != null)
                {
                    done = ri.DrawGlyphs(gp.GlyphRun, gp.GetRectBounds(true), p.Transform, desp);

                    if (!done)
                    {
                        g = p.WidenGeometry;
                    }
                }

                if (!done)
                {
                    if (!p.Transform.IsIdentity)
                    {
                        // Should not occur; GeometryPrimitive.ApplyTransform will push transform
                        // to geometry and brush.
                        g = Utility.TransformGeometry(g, p.Transform);

                        if (ri.Brush != null)
                        {
                            ri.Brush = ri.Brush.ApplyTransformCopy(p.Transform);
                        }

                        if (ri.Pen != null && ri.Pen.StrokeBrush != null)
                        {
                            ri.Pen             = ri.Pen.Clone();
                            ri.Pen.StrokeBrush = ri.Pen.StrokeBrush.ApplyTransformCopy(p.Transform);
                        }
                    }

                    ri.DrawGeometry(g, desp, p);
                }

                return;
            }

            ImagePrimitive ip = primitive as ImagePrimitive;

            if (ip != null)
            {
                ri.RenderImage(ip.Image, ip.DstRect, ip.Clip, ip.Transform, desp);
            }
            else
            {
                Debug.Assert(false, "Wrong Primitive type");
            }
        }