Exemple #1
0
        // Draw the pattern using the texture brush.
        void DrawPatternWithTexBrush(GraphicsTarget g, SymPathWithHoles path, float angle, SymColor color, RenderOptions renderOpts)
        {
            Brush brush = (Brush) patternBrushes[color];
            Debug.Assert(brush != null);

            if (angle != 0.0F) {
                object graphicsState = g.Save();

                try {
                    // Set the clipping region to draw only inside the area.
                    g.SetClip(path);

                    // use a transform to rotate.
                    Matrix matrix = GraphicsUtil.RotationMatrix(angle, new PointF(0, 0));
                    g.Transform(matrix);

                    // Get the correct bounding rect.
                    RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -angle);

                    g.FillRectangle(brush, bounding);
                }
                finally {
                    // restore the clip region and the transform
                    g.Restore(graphicsState);
                }
            }
            else {
                path.Fill(g, brush);
            }
        }
Exemple #2
0
        // Draw the pattern (at the given angle) inside the path.
        void DrawPattern(GraphicsTarget g, SymPathWithHoles path, float angle, SymColor color, RenderOptions renderOpts)
        {
            object graphicsState = g.Save();

            try {
                // Set the clipping region to draw only inside the area.
                g.SetClip(path);

                // use a transform to rotate
                Matrix matrix = GraphicsUtil.RotationMatrix(patternAngle + angle, new PointF(0, 0));
                g.Transform(matrix);

                // Get the correct bounding rect.
                RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(patternAngle + angle));

                DrawPatternRows(g, bounding, color, renderOpts);
            }
            finally {
                // restore the clip region and the transform
                g.Restore(graphicsState);
            }
        }
Exemple #3
0
        // Draw the hatching into the interior of the SymPath.
        void DrawHatching(GraphicsTarget g, SymPathWithHoles path, float angle, RenderOptions renderOpts)
        {
            object graphicsState = g.Save();

            try {
                // Set the clipping region to draw only inside the area.
                g.SetClip(path);

                // use a transform to rotate and then draw hatching.
                Matrix matrix = GraphicsUtil.RotationMatrix(hatchAngle1 + angle, new PointF(0, 0));
                g.Transform(matrix);

                // Get the correct bounding rect.
                RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(hatchAngle1 + angle));

                DrawHatchLines(g, hatchPen, hatchSpacing, bounding, renderOpts);

                // and again for the second bound of hatching
                if (hatchMode == 2) {
                    // Get the correct bounding rect.
                    bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(hatchAngle2 + angle));

                    matrix = GraphicsUtil.RotationMatrix(hatchAngle2 - hatchAngle1, new PointF(0, 0));
                    g.Transform(matrix);
                    DrawHatchLines(g, hatchPen, hatchSpacing, bounding, renderOpts);
                }
            }
            finally {
                // restore the clip region and the transform
                g.Restore(graphicsState);
            }
        }
Exemple #4
0
        // Draw this text symbol along a path.
        internal void DrawTextOnPath(GraphicsTarget g, SymPath path, string text, SymColor color, RenderOptions renderOpts)
        {
            if (color == null)
                return;
            if (color != fontColor && (framing.framingStyle == FramingStyle.None || color != framing.framingColor))
                return;

            if (!objectsCreated)
                CreateObjects();

            // Get the location of each grapheme to print.
            List<GraphemePlacement> graphemeList = GetLineTextGraphemePlacement(path, text);
            PointF topAscentPoint = new PointF(0, -FontAscent);    // Drawing is relative to top of char, we want to draw at baseline.

            foreach (GraphemePlacement grapheme in graphemeList) {
                object graphicsState;
                graphicsState = g.Save();

                try {
                    // Move location to draw at to the origin, set angle for drawing text.
                    Matrix matrix = GraphicsUtil.TranslationMatrix(grapheme.pointStart.X, grapheme.pointStart.Y);
                    matrix = GraphicsUtil.Multiply(GraphicsUtil.ScalingMatrix(1, -1), matrix);      // Reverse Y so text is correct way aroun
                    matrix = GraphicsUtil.Multiply(GraphicsUtil.RotationMatrix(-grapheme.angle, new PointF(0,0)), matrix);
                    g.Transform(matrix);

                    DrawStringWithEffects(g, color, grapheme.grapheme, topAscentPoint);
                }
                finally {
                    g.Restore(graphicsState);  // restore transform
                }
            }
        }
Exemple #5
0
        // Draw this text symbol at point pt with angle ang in this graphics (given color only).
        internal void Draw(GraphicsTarget g, string[] text, float[] lineWidths, PointF location, float angle,  float fullWidth, SymColor color, RenderOptions renderOpts)
        {
            if (color == null)
                return;
            if (color != fontColor && (framing.framingStyle == FramingStyle.None || color != framing.framingColor) && (!underline.underlineOn || color != underline.underlineColor))
                return;

            if (!objectsCreated)
                CreateObjects();

            // Move location to draw at to the origin.
            object graphicsState = g.Save();

            Matrix matrix = GraphicsUtil.TranslationMatrix(location.X, location.Y);
            matrix = GraphicsUtil.Multiply(GraphicsUtil.ScalingMatrix(1, -1), matrix); // Reverse Y direction so text is correct way around.
            if (angle != 0)
                matrix = GraphicsUtil.Multiply(GraphicsUtil.RotationMatrix(-angle, new PointF(0,0)), matrix);
            g.Transform(matrix);

            try {
                // Draw all the lines of text.
                PointF pt = new PointF(0F, 0F);
                float baselineOfLine = 0;          // y coordinate of baseline of line.
                bool firstLineOfPara = true, lastLineOfPara;
                for (int lineIndex = 0; lineIndex < text.Length; ++lineIndex) {
                    string line = text[lineIndex];
                    float lineWidth = lineWidths[lineIndex];

                    lastLineOfPara = (lineIndex == text.Length - 1 || text[lineIndex + 1] == ParagraphMark);        // are we on the last line of a paragraph?

                    if (line == ParagraphMark) {
                        pt.Y += paraSpacing;
                        firstLineOfPara = true;
                    }
                    else {
                        float indent = 0;
                        float leftEdge;          // tabs are relative to this X position.
                        if (fontAlign == TextSymDefAlignment.Right)
                            pt.X = leftEdge = -lineWidth;
                        else if (fontAlign == TextSymDefAlignment.Center)
                            pt.X = leftEdge = -(lineWidth / 2F);
                        else {
                            leftEdge = 0;
                            pt.X = indent = firstLineOfPara ? firstIndent : restIndent;     // indents only used for left align or justified
                        }

                        // Get the size of spaces. Justification is done by adjusting this.
                        float sizeOfSpace = wordSpacing * spaceWidth;            // basic width of spaces as set by the symdef
                        if (fontAlign == TextSymDefAlignment.Justified && !lastLineOfPara && fullWidth > 0)
                            sizeOfSpace += JustifyText(line, lineWidth, fullWidth - indent);

                        // Draw all the text segments in the line. (A text segment is a word, unless charSpacing>0, in which case it is graphemes).
                        int index = 0;
                        for (; ; ) {
                            string textSegment;

                            if (charSpacing > 0)
                                textSegment = StringInfo.GetNextTextElement(line.Substring(index));
                            else
                                textSegment = GetNextTextSegment(line.Substring(index));
                            if (string.IsNullOrEmpty(textSegment))
                                break;

                            if (textSegment == " ")
                                pt.X += sizeOfSpace;
                            else if (textSegment == "\t")
                                pt.X += WidthOfTextSegment("\t", pt.X - leftEdge);
                            else {
                                DrawStringWithEffects(g, color, textSegment, pt);
                                pt.X += MeasureStringWidth(textSegment);

                                if (charSpacing > 0)
                                    pt.X += charSpacing * spaceWidth;
                            }

                            index += textSegment.Length;
                        }

                        baselineOfLine = pt.Y + FontAscent;        // Set the bottom of the text.

                        if (lastLineOfPara)
                            DrawUnderline(g, color, baselineOfLine, Math.Max(fullWidth, lineWidth), (fullWidth == 0) ? indent : 0);

                        pt.Y += lineSpacing;
                        firstLineOfPara = false;
                    }
                }

                // Draw the framing rectangle, if any.
                if (underline.underlineOn)
                    baselineOfLine += underline.underlineDistance + underline.underlineWidth;
                DrawFramingRectangle(g, lineWidths, fullWidth, color, baselineOfLine);
            }
            finally {
                g.Restore(graphicsState);
            }
        }
Exemple #6
0
        internal void Draw(GraphicsTarget g, PointF pt, float angle, Matrix extraTransform, float[] gaps, SymColor color, RenderOptions renderOpts)
        {
            Debug.Assert(constructed);

            if (! simple || gaps != null || !extraTransform.IsIdentity) {
                object graphicsState = null;
                for (int i = 0; i < parts.Length; ++i) {
                    if (parts[i].color == color) {
                        // Establish transformation matrix.
                        if (graphicsState == null) {
                            graphicsState = g.Save();

                            Matrix matrix = GraphicsUtil.Multiply(GraphicsUtil.RotationMatrix(angle, new PointF(0,0)), GraphicsUtil.TranslationMatrix(pt.X, pt.Y));
                            if (extraTransform != null)
                                matrix = GraphicsUtil.Multiply(extraTransform, matrix);

                            g.Transform(matrix);
                        }
                        parts[i].Draw(g, gaps, renderOpts);
                    }
                }

                if (graphicsState != null)
                    g.Restore(graphicsState);
            }
            else if (color == parts[0].color) {
                DrawSimple(g, pt, renderOpts);
            }
        }