Exemple #1
0
        Glyph CreateGlyph(OcadSymbolElt[] elts)
        {
            if (elts == null)
                return null;

            Glyph glyph = new Glyph();

            foreach (OcadSymbolElt elt in elts) {
                SymColor color = GetColor(elt.stColor);

                switch (elt.stType) {
                case 1: // line
                    glyph.AddLine(color, CreateSymPath(elt.stCoords), ToWorldDimensions(elt.stLineWidth), ImportLineStyle((short) elt.stFlags));
                    break;
                case 2: // area
                    SymPathWithHoles areaPath = CreateAreaSymPath(elt.stCoords);
                    glyph.AddArea(color, areaPath);
                    break;
                case 3: // circle
                    float width = ToWorldDimensions(elt.stLineWidth);
                    float diameter = ToWorldDimensions(elt.stDiameter);
                    if (version > 8)
                        diameter += width;              // diameter is from middle of line in OCAD 9+, from outer edges in OCAD 6-8.
                    glyph.AddCircle(color, PointFromOcadCoord(elt.stCoords[0]), width, diameter);
                    break;
                case 4:
                    glyph.AddFilledCircle(color, PointFromOcadCoord(elt.stCoords[0]), ToWorldDimensions(elt.stDiameter));
                    break;
                default:
                    throw new OcadFileFormatException("Invalid symbol element kind {0}", elt.stType);
                }
            }

            glyph.ConstructionComplete();

            return glyph;
        }
Exemple #2
0
        OcadSymbolElt[] SymbolEltsFromGlyph(Glyph glyph, out short datasize)
        {
            Glyph.GlyphPart[] parts = glyph.GetParts();
            OcadSymbolElt[] elts = new OcadSymbolElt[parts.Length];

            datasize = 0;

            for (int i = 0; i < parts.Length; ++i) {
                elts[i] = SymbolEltFromGlyphPart(parts[i]);
                datasize += (short) (2 + elts[i].stnPoly);
            }

            return elts;
        }
Exemple #3
0
		public static void WriteElements(BinaryWriter writer, OcadSymbolElt[] elts) {
			if (elts != null) {
				foreach (OcadSymbolElt elt in elts)
					elt.Write(writer);
			}
		}
Exemple #4
0
        OcadSymbolElt SymbolEltFromGlyphPart(Glyph.GlyphPart part)
        {
            OcadSymbolElt elt = new OcadSymbolElt();

            elt.stColor = NumberOfColor(part.color);

            switch (part.kind) {
            case GlyphPartKind.Area:
                elt.stType = 2;
                elt.stCoords = CoordsFromSymPathWithHoles(part.areaPath);
                break;

            case GlyphPartKind.Line:
                elt.stType = 1;
                elt.stFlags = (ushort) OcadLineStyle(part.lineStyle);
                elt.stLineWidth = (short) ToOcadDimensions(part.lineWidth);
                elt.stCoords = CoordsFromSymPath(part.path);
                break;

            case GlyphPartKind.Circle:
                elt.stType = 3;
                elt.stLineWidth = (short) ToOcadDimensions(part.lineWidth);
                if (version > 8)
                    elt.stDiameter = (short) ToOcadDimensions(part.circleDiam - part.lineWidth);
                else
                    elt.stDiameter = (short) ToOcadDimensions(part.circleDiam);
                elt.stCoords = new OcadCoord[1] { OcadCoordFromPoint(part.point) };
                break;

            case GlyphPartKind.FilledCircle:
                elt.stType = 4;
                elt.stDiameter = (short) ToOcadDimensions(part.circleDiam);
                elt.stCoords = new OcadCoord[1] { OcadCoordFromPoint(part.point) };
                break;

            default:
                Debug.Fail("bad GlyphPartKind");
                break;
            }

            elt.stnPoly = (short) elt.stCoords.Length;
            return elt;
        }
Exemple #5
0
		static public OcadSymbolElt[] ReadElements(BinaryReader reader, int DataSize) {
            List<OcadSymbolElt> list = new List<OcadSymbolElt>();

			while (DataSize > 0) {
				OcadSymbolElt elt = new OcadSymbolElt();
				DataSize -= elt.Read(reader);
				list.Add(elt);
			}
			Debug.Assert(DataSize == 0);

			return list.ToArray();
		}