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); }
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; }
static public OcadSymbol Read(BinaryReader reader, int version) { int Size; int Sym = 0; short Otp; byte SymTp = 0; if (version <= 8) { Size = reader.ReadInt16(); Sym = reader.ReadInt16(); Otp = reader.ReadInt16(); SymTp = reader.ReadByte(); } else { Size = reader.ReadInt32(); Sym = reader.ReadInt32(); Otp = reader.ReadByte(); } byte Flags = reader.ReadByte(); OcadSymbol sym; if (Otp == 1) { sym = new OcadPointSymbol(); } else if (Otp == 2 && SymTp == 0) sym = new OcadLineSymbol(); else if (Otp == 2 && SymTp == 1) sym = new OcadLineTextSymbol(); else if (Otp == 3) sym = new OcadAreaSymbol(); else if (Otp == 4) sym = new OcadTextSymbol(); else if (Otp == 5 || Otp == 7) sym = new OcadRectSymbol(); else if (Otp == 6) sym = new OcadLineTextSymbol(); else { Debug.Assert(false); return null; } sym.Size = Size; sym.Sym = Sym; sym.Otp = Otp; sym.SymTp = SymTp; sym.Flags = Flags; if (version <= 8) sym.Extent = reader.ReadInt16(); sym.Selected = (reader.ReadByte() != 0) ? true : false; sym.Status = reader.ReadByte(); if (version <= 8) { sym.Tool = reader.ReadInt16(); sym.FrWidth = reader.ReadInt16(); } else { sym.Tool = reader.ReadByte(); sym.CsMode = reader.ReadByte(); sym.CsObjType = reader.ReadByte(); sym.CsCdFlags = reader.ReadByte(); sym.Extent = reader.ReadInt32(); } sym.FilePos = reader.ReadInt32(); if (version <= 8) { sym.ColorSet = Util.ReadByteArray(reader, 32); } else { sym.Group = reader.ReadInt16(); sym.nColors = reader.ReadInt16(); sym.ColorsUsed = new short[sym.nColors]; for (int i = 0; i < 14; ++i) { short colorId = reader.ReadInt16(); if (i < sym.nColors) sym.ColorsUsed[i] = colorId; } } sym.Description = Util.ReadDelphiString(reader, 31); sym.IconBits = Util.ReadByteArray(reader, (version <= 8) ? 264 : 484); sym.ReadExtra(reader, version); return sym; }