Beispiel #1
0
        SymDef CreateLineTextSymdef(string name, int ocadID, OcadLineTextSymbol ocadSym)
        {
            SymColor fontColor;
            bool bold, italic;
            TextSymDef symdef;
            float fontSize;
            float charSpacing;
            float wordSpacing;
            TextSymDefAlignment fontAlign;

            fontColor = GetColor(ocadSym.FontColor);

            italic = ocadSym.Italic;
            bold = (ocadSym.Weight >= 500);

            if (ocadSym.Alignment == 1)
                fontAlign = TextSymDefAlignment.Center;
            else if (ocadSym.Alignment == 2)
                fontAlign = TextSymDefAlignment.Right;
            else if (ocadSym.Alignment == 3)
                fontAlign = TextSymDefAlignment.Justified;
            else
                fontAlign = TextSymDefAlignment.Left;

            // ocadSym.FontSize is in 10ths of a point. Convert to mm.
            fontSize = ocadSym.FontSize / 720F * 25.4F;

            charSpacing = ocadSym.CharSpace / 100F;
            wordSpacing = ocadSym.WordSpace / 100F;

            symdef = new TextSymDef(name, ocadID);

            symdef.SetFont(ocadSym.FontName, fontSize, bold, italic, fontColor, fontSize, 0F, 0F, 0F, null, charSpacing, wordSpacing, fontAlign);

            // handle framing.
            ReadFraming(ocadSym.FrMode, ocadSym.FrFlags, ocadSym.FrColor, ocadSym.FrWidth, ocadSym.FrSize, ocadSym.FrOfX, ocadSym.FrOfY, 0, 0, 0, 0, symdef);

            return symdef;
        }
Beispiel #2
0
        // Apply framing to a text sym.
        private void ReadFraming(byte ocadFrMode, byte ocadFrFlags, short ocadFrColor, short ocadFrWidth, short ocadFrSize, short ocadFrOfX, short ocadFrOfY, short ocadFrLeft, short ocadFrTop, short ocadFrRight, short ocadFrBottom, TextSymDef symdef)
        {
            if (ocadFrMode == 2 && version >= 7) {
                // line framing
                TextSymDef.Framing framing = new TextSymDef.Framing();
                framing.framingStyle = TextSymDef.FramingStyle.Line;
                if (version == 7)
                    framing.lineWidth = ToWorldDimensions(ocadFrWidth);
                else
                    framing.lineWidth = ToWorldDimensions(ocadFrSize);
                framing.framingColor = GetColor(ocadFrColor);
                if (ocadFrFlags == 1) {
                    framing.lineStyle = LineStyle.Rounded;
                }
                else if (ocadFrFlags == 2) {
                    framing.lineStyle = LineStyle.Beveled;
                }
                else if (ocadFrFlags == 3 ||ocadFrFlags == 0) {
                    framing.lineStyle = LineStyle.Mitered;
                }

                symdef.SetFraming(framing);
            }
            else if (ocadFrMode == 1 && version >= 9) {
                // Shadow framing
                TextSymDef.Framing framing = new TextSymDef.Framing();
                framing.framingStyle = TextSymDef.FramingStyle.Shadow;
                framing.framingColor = GetColor(ocadFrColor);
                framing.shadowX = ToWorldDimensions(ocadFrOfX);
                framing.shadowY = ToWorldDimensions(ocadFrOfY);

                symdef.SetFraming(framing);
            }
            else if (ocadFrMode == 3 && version >= 9) {
                // rectangle framing
                TextSymDef.Framing framing = new TextSymDef.Framing();
                framing.framingStyle = TextSymDef.FramingStyle.Rectangle;
                framing.framingColor = GetColor(ocadFrColor);
                framing.rectBorderLeft = ToWorldDimensions(ocadFrLeft);
                framing.rectBorderRight = ToWorldDimensions(ocadFrRight);
                framing.rectBorderTop = ToWorldDimensions(ocadFrTop);
                framing.rectBorderBottom = ToWorldDimensions(ocadFrBottom);

                symdef.SetFraming(framing);
            }
            else if (ocadFrMode == 1 && version <= 7) {
                // Framing font. Just use the offset and ignore the font.
                TextSymDef.Framing framing = new TextSymDef.Framing();
                framing.framingStyle = TextSymDef.FramingStyle.Shadow;
                framing.framingColor = GetColor(ocadFrColor);
                framing.shadowX = ToWorldDimensions(ocadFrOfX);
                framing.shadowY = ToWorldDimensions(ocadFrOfY);

                symdef.SetFraming(framing);
            }
        }
Beispiel #3
0
        LineTextSymbol CreateLineTextSymbol(OcadObject obj, TextSymDef symdef)
        {
            if (symdef == null)
                throw new OcadFileFormatException("Object has unknown or inconsistent symbol type {0}", obj.Sym);

            if (obj.coords == null || obj.coords.Length < 2)
                return null;

            SymPath path = CreateSymPath(obj.coords);
            string text = obj.text;

            CheckFont(symdef.FontName);

            return new LineTextSymbol(symdef, path, text);
        }
Beispiel #4
0
        TextSymbol CreateTextSymbol(OcadObject obj, TextSymDef symdef, bool formatted)
        {
            if (symdef == null)
                throw new OcadFileFormatException("Object has unknown or inconsistent symbol type {0}", obj.Sym);

            string text = obj.text;

            PointF location;
            float width, topAdjust;
            float angle = AngleToDegrees(obj.Ang);

            if (formatted) {
                location = PointFromOcadCoord(obj.coords[3]);
                width = Util.DistanceF(location, PointFromOcadCoord(obj.coords[2]));

                // OCAD adds an extra internal leading (incorrectly).
                topAdjust = symdef.FontEmHeight - (symdef.FontAscent + symdef.FontDescent);
            }
            else {
                location = PointFromOcadCoord(obj.coords[0]);
                width = 0;

                // OCAD positions by baseline of text, we position at top of ascent of text.
                topAdjust = symdef.FontAscent;
            }

            location.Y += (float) (topAdjust * Math.Sin((angle + 90.0) / 360.0 * 2 * Math.PI));
            location.X += (float) (topAdjust * Math.Cos((angle + 90.0) / 360.0 * 2 * Math.PI));

            string[] lines = Util.SplitLines(text);

            CheckFont(symdef.FontName);

            return new TextSymbol(symdef, lines, location, angle, width);
        }
Beispiel #5
0
        SymDef CreateTextSymdef(string name, int ocadID, OcadTextSymbol ocadSym)
        {
            SymColor fontColor;
            bool bold, italic;
            TextSymDef symdef;
            float fontSize;
            float paraSpacing;
            float firstIndent, restIndent;
            float charSpacing, wordSpacing;
            float[] tabs;
            TextSymDefAlignment fontAlign;

            fontColor = GetColor(ocadSym.FontColor);

            italic = ocadSym.Italic;
            bold = (ocadSym.Weight >= 500);

            if (ocadSym.Alignment == 1)
                fontAlign = TextSymDefAlignment.Center;
            else if (ocadSym.Alignment == 2)
                fontAlign = TextSymDefAlignment.Right;
            else if (ocadSym.Alignment == 3)
                fontAlign = TextSymDefAlignment.Justified;
            else
                fontAlign = TextSymDefAlignment.Left;

            // ocadSym.FontSize is in 10ths of a point. Convert to mm.
            fontSize = ocadSym.FontSize / 720F * 25.4F;

            paraSpacing = ToWorldDimensions(ocadSym.ParaSpace);   // paragraph spacing in mm.
            firstIndent = ToWorldDimensions(ocadSym.IndentFirst);       // indent first line in mm.
            restIndent = ToWorldDimensions(ocadSym.IndentOther);    // indent rest lines in mm.
            charSpacing = ocadSym.CharSpace / 100F;
            wordSpacing = ocadSym.WordSpace / 100F;
            if (ocadSym.LBOn) {
                paraSpacing += ToWorldDimensions(ocadSym.LBDist + ocadSym.LBWidth);   // underlining counts in paragraph spacing.
            }

            tabs = null;
            if (ocadSym.nTabs > 0) {
                tabs = new float[ocadSym.nTabs];
                for (int i = 0; i < ocadSym.nTabs; ++i)
                    tabs[i] = ToWorldDimensions(ocadSym.Tabs[i]);
            }

            symdef = new TextSymDef(name, ocadID);

            symdef.SetFont(ocadSym.FontName, fontSize, bold, italic, fontColor, fontSize * ocadSym.LineSpace / 100F, paraSpacing, firstIndent, restIndent, tabs, charSpacing, wordSpacing, fontAlign);

            // handle framing.
            ReadFraming(ocadSym.FrMode, ocadSym.FrFlags, ocadSym.FrColor, ocadSym.FrWidth, ocadSym.FrSize, ocadSym.FrOfX, ocadSym.FrOfY, ocadSym.FrLeft, ocadSym.FrTop, ocadSym.FrRight, ocadSym.FrBottom, symdef);

            if (ocadSym.LBOn) {
                TextSymDef.Underlining underline = new TextSymDef.Underlining();
                underline.underlineOn = true;
                underline.underlineColor = GetColor(ocadSym.LBColor);
                underline.underlineDistance = ToWorldDimensions(ocadSym.LBDist);
                underline.underlineWidth = ToWorldDimensions(ocadSym.LBWidth);
                symdef.SetUnderline(underline);
            }

            return symdef;
        }
Beispiel #6
0
 // If a rectangle symbol include a grid, then we create extra line and text symbols
 // to handle the grid and numbers in the grid.
 void CreateRectangleGridSymdefs(string name, SymColor color, out LineSymDef lineSymdef, out TextSymDef textSymdef)
 {
     // UNDONE: Really should check that a real
     // UNDONE: symbol isn't using these ids, or that there aren't already synthetic symbols that match.
     lineSymdef = new LineSymDef(name + " grid lines", ocadIdNext++, color, 0.15F, LineStyle.Beveled);
     textSymdef = new TextSymDef(name + " grid text", ocadIdNext++);
     textSymdef.SetFont("Arial", 15F / 72F * 25.4F, true, false, color, 0, 0, 0, 0, null, 0, 1F, TextSymDefAlignment.Left);
     map.AddSymdef(lineSymdef);
     map.AddSymdef(textSymdef);
 }
Beispiel #7
0
        // Set the framing parts.
        private void WriteFraming(TextSymDef symdef, out byte ocadFrMode, out byte ocadFrFlags, out string ocadFrName, out short ocadFrColor, out short ocadFrWidth, out short ocadFrSize, 
                                                  out short ocadFrWeight, out bool ocadFrItalic, out short ocadFrOfX, out short ocadFrOfY, out short ocadFrLeft, out short ocadFrTop, out short ocadFrRight, out short ocadFrBottom)
        {
            TextSymDef.Framing framing = symdef.FramingInfo;
            ocadFrMode = ocadFrFlags = 0;
            ocadFrColor = ocadFrWidth = ocadFrSize = ocadFrOfX = ocadFrOfY =
                                     ocadFrLeft = ocadFrTop = ocadFrRight = ocadFrBottom = 0;
            ocadFrWeight = 400;
            ocadFrItalic = false;
            ocadFrName = "";

            switch (framing.framingStyle) {
            case TextSymDef.FramingStyle.None:
                break;

            case TextSymDef.FramingStyle.Line:
                if (version >= 7) {
                    ocadFrMode = 2;
                    if (version == 7)
                        ocadFrWidth = (short) ToOcadDimensions(framing.lineWidth);
                    else
                        ocadFrSize = (short) ToOcadDimensions(framing.lineWidth);
                    ocadFrColor = NumberOfColor(framing.framingColor);
                    if (framing.lineStyle == LineStyle.Rounded)
                        ocadFrFlags = 1;
                    else if (framing.lineStyle == LineStyle.Beveled)
                        ocadFrFlags = 2;
                    else
                        ocadFrFlags = 3;
                }
                break;

            case TextSymDef.FramingStyle.Shadow:
                if (version >= 9) {
                    ocadFrMode = 1;
                    ocadFrColor = NumberOfColor(framing.framingColor);
                    ocadFrOfX = (short) ToOcadDimensions(framing.shadowX);
                    ocadFrOfY = (short) ToOcadDimensions(framing.shadowY);
                }
                else if (version <= 7) {
                    ocadFrMode = 1;
                    ocadFrColor = NumberOfColor(framing.framingColor);
                    ocadFrOfX = (short) ToOcadDimensions(framing.shadowX);
                    ocadFrOfY = (short) ToOcadDimensions(framing.shadowY);
                    ocadFrName = symdef.FontName;
                    ocadFrItalic = symdef.Italic;
                    ocadFrWeight = (short) (symdef.Bold ? 700 : 400);
                    ocadFrSize = (short) Math.Round(symdef.FontEmHeight / 25.4F * 720F);
                }
                break;

            case TextSymDef.FramingStyle.Rectangle:
                if (version >= 9) {
                    ocadFrMode = 3;
                    ocadFrColor = NumberOfColor(framing.framingColor);
                    ocadFrLeft = (short) ToOcadDimensions(framing.rectBorderLeft);
                    ocadFrTop = (short) ToOcadDimensions(framing.rectBorderTop);
                    ocadFrRight = (short) ToOcadDimensions(framing.rectBorderRight);
                    ocadFrBottom = (short) ToOcadDimensions(framing.rectBorderBottom);
                }
                break;
            }
        }
Beispiel #8
0
        void WriteTextSymDef(TextSymDef symdef)
        {
            OcadTextSymbol symbol = new OcadTextSymbol();
            FillInCommonSymdef(symbol, symdef);

            symbol.Otp = 4;
            symbol.SymTp = 1;

            if (symdef.FontColor != null)
                symbol.FontColor = NumberOfColor(symdef.FontColor);
            symbol.Italic = symdef.Italic;
            if (symdef.Bold)
                symbol.Weight = 700;
            else
                symbol.Weight = 400;
            if (symdef.FontAlignment == TextSymDefAlignment.Justified)
                symbol.Alignment = 3;
            if (symdef.FontAlignment == TextSymDefAlignment.Right)
                symbol.Alignment = 2;
            else if (symdef.FontAlignment == TextSymDefAlignment.Center)
                symbol.Alignment = 1;
            symbol.FontSize = (short) Math.Round(symdef.FontEmHeight / 25.4F * 720F);
            symbol.FontName = symdef.FontName;
            symbol.LineSpace = (short) Math.Round(symdef.LineSpacing * 100F / symdef.FontEmHeight);
            if (symdef.Underline.underlineOn)
                symbol.ParaSpace = (short) ToOcadDimensions(symdef.ParaSpacing - symdef.Underline.underlineDistance - symdef.Underline.underlineWidth);
            else
                symbol.ParaSpace = (short) ToOcadDimensions(symdef.ParaSpacing);
            symbol.IndentFirst = (short) ToOcadDimensions(symdef.FirstIndent);
            symbol.IndentOther = (short) ToOcadDimensions(symdef.RestIndent);
            symbol.CharSpace = (short) Math.Round(symdef.CharSpacing * 100F);
            symbol.WordSpace = (short) Math.Round(symdef.WordSpacing * 100F);

            float[] tabs = symdef.Tabs;
            if (tabs != null && tabs.Length > 0) {
                symbol.nTabs = (short) Math.Min(32, tabs.Length);
                for (int i = 0; i < symbol.nTabs; ++i)
                    symbol.Tabs[i] = (short) ToOcadDimensions(tabs[i]);
            }

            WriteFraming(symdef, out symbol.FrMode, out symbol.FrFlags, out symbol.FrName, out symbol.FrColor, out symbol.FrWidth,
                                  out symbol.FrSize, out symbol.FrWeight, out symbol.FrItalic, out symbol.FrOfX, out symbol.FrOfY, out symbol.FrLeft, out symbol.FrTop, out symbol.FrRight, out symbol.FrBottom);

            TextSymDef.Underlining underline = symdef.Underline;
            if (underline.underlineOn) {
                symbol.LBOn = true;
                symbol.LBColor = NumberOfColor(underline.underlineColor);
                symbol.LBDist = (short) ToOcadDimensions(underline.underlineDistance);
                symbol.LBWidth = (short) ToOcadDimensions(underline.underlineWidth);
            }

            symbol.Write(writer, version);
        }
Beispiel #9
0
        string[] wrappedText; // text after being word wrapped.

        #endregion Fields

        #region Constructors

        public TextSymbol(TextSymDef def, string[] text, PointF location, float angle, float width)
        {
            this.def = def; this.location = location;
            this.rotation = angle; this.width = width;
            this.text = text;

            // For text that is wrapped and center or right aligned, the adjusted location
            // is the location that the text is aligned on.
            adjustedLocation = location;
            if (width > 0) {
                if (def.FontAlignment == TextSymDefAlignment.Right)
                    adjustedLocation = Util.MoveDistance(adjustedLocation, width, angle);
                else if (def.FontAlignment == TextSymDefAlignment.Center)
                    adjustedLocation = Util.MoveDistance(adjustedLocation, width / 2, angle);
            }

            if (width > 0)
                wrappedText = def.BreakLines(text, width, out wrappedLineWidths);
            else
                wrappedText = def.BreakUnwrappedLines(text, out wrappedLineWidths); // no wrapping.

            boundingBox = def.CalcBounds(wrappedText, wrappedLineWidths, adjustedLocation, rotation, width, out size);
        }
Beispiel #10
0
        public LineTextSymbol(TextSymDef def, SymPath path, string text)
        {
            path.CheckConstructed();
            this.def = def; this.path = path; this.text = text;

            boundingBox = def.CalcBounds(path, text);
        }