Example #1
0
 public static RTType MakeType(Command c, CGMImage parent)
 {
     RTType type;
     int typ = BinaryUtil.makeIndex(c, parent.IntPrecision);
     switch (typ)
     {
         case 1:
             type = RTType.BASIC;
             break;
         case 2:
             type = RTType.BOXED_CAP;
             break;
         case 3:
             type = RTType.BOXED_ALL;
             break;
         case 4:
             type = RTType.ISOTROPIC_CAP;
             break;
         case 5:
             type = RTType.ISOTROPIC_ALL;
             break;
         case 6:
             type = RTType.JUSTIFIED;
             break;
         default:
             type = RTType.BASIC;
             break;
     }
     return type;
 }
Example #2
0
        public static string getString(Command cmd, bool forceunicode)
        {
            bool UnicodeCgm = forceunicode;
            Encoding enc = Encoding.ASCII;

            int length = cmd.ParamGet(cmd.CurrentArg++);
            int cb = cmd.ParamGet(cmd.CurrentArg++);

            if (cb == 0x1b || cb == 0 || UnicodeCgm)
            {
                enc = Encoding.Unicode;
                //cmd.CurrentArg += 2;//0x252f
                //length -= 2;
                UnicodeCgm = true;
            }
            else cmd.CurrentArg--;
            //return "";
            if (length == 255)
            {
                length = makeUInt16(cmd);
                if ((length & (1 << 16)) != 0)
                {
                    length = (length << 16) | makeUInt16(cmd);
                }

            }
            byte[] c = new byte[length];
            for (int i = 0; i < length; i++)
            {
                if (cmd.CurrentArg >= cmd.ParamsLength) break;
                c[i] = (byte)makeByte(cmd);
            }
            return enc.GetString(c);
        }
Example #3
0
        public CGMRestrictedText(Command c, CGMImage parent)
        {
            deltaWidth = BinaryUtil.makeVdc(c, parent.VDCtype, parent.VDCRealType, parent.IntPrecision);
            deltaHeight = BinaryUtil.makeVdc(c, parent.VDCtype, parent.VDCRealType, parent.IntPrecision);
            position = BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.IntPrecision);

            finalNotFinal = BinaryUtil.makeEnum(c);
            Text = BinaryUtil.getString(c);

            type = parent.RestrictedTextType;
        }
Example #4
0
        public void loadFile(Stream s)
        {
            Command c;

            while (s.Position < s.Length - 1)
            {
                c = new Command(s);
                if (cml != null)
                    commands.Add(cml(c));
                else
                    commands.Add(c);
            }
        }
Example #5
0
        public CGMScalingMode(Command c, CGMImage parent)
        {
            int mod = BinaryUtil.makeEnum(c);
            if (mod == 0)
            {
                this.mode = CGMScalingModeMode.ABSTRACT;
            }
            else if (mod == 1)
            {
                this.mode = CGMScalingModeMode.METRIC;
                this.metricScalingFactor = BinaryUtil.makeFloatingPoint(c, parent.RealPrecision);

                // make sure all the arguments were read
                //Debug.Assert((this.currentArg == this.args.length));
            }
        }
Example #6
0
 public CGMPolyLine(Command c, CGMImage parent)
 {
     points = new List<PointD>();
     int n = c.ParamsLength / BinaryUtil.sizeOfPoint(parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision);
     //p = new System.Drawing.Drawing2D.GraphicsPath();
     PointD lp = new PointD();
     for (int i = 0; i < n; i++)
     {
         PointD point = BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision);
         //if (i == 0)
         //{
         //    //this.path.moveTo(point.x, point.y);
         //}
         //else
         //{
         //    //this.path.lineTo(point.x, point.y);
         //    //p.AddLine((float)lp.x, (float)lp.y,
         //    //    (float)point.x, (float)point.y);
         //}
         points.Add(point);
         lp = point;
     }
 }
Example #7
0
 public static string getFontList(Command c)
 {
     int count = 0, i = 0;
     while (i < c.ParamsLength)
     {
         count++;
         i += c.ParamGet(i) + 1;
     }
     string[] fontNames = new string[count];
     count = 0;
     i = 0;
     while (i < c.ParamsLength)
     {
         int cl = c.ParamGet(i);
         if (cl == 0) break;
         byte[] a = new byte[cl];
         for (int j = 0; j < cl; j++)
             a[j] = (byte)c.ParamGet(i + j + 1);
         fontNames[count] = BinaryUtil.AsString(a);
         count++;
         i += c.ParamGet(i) + 1;
     }
     return BinaryUtil.AsString(fontNames);
 }
Example #8
0
 public static int makeIndex(Command c, int IntPrecision)
 {
     return makeInt(c, IntPrecision);
 }
Example #9
0
 string _RealPrecision(Command c)
 {
     int representation = BinaryUtil.makeEnum(c);
     int p2 = BinaryUtil.makeInt(c, IntPrecision);
     int p3 = BinaryUtil.makeInt(c, IntPrecision);
     if (representation == 0)
     {
         if (p2 == 9 && p3 == 23)
         {
             RealPrecision = 321;//Precision.FLOATING_32;
             return "FLOATING_32";
         }
         else if (p2 == 12 && p3 == 52)
         {
             RealPrecision = 641;//Precision.FLOATING_64;
             return "FLOATING_64";
         }
         else
         {
             //Debug.Assert(false, "unsupported combination");
         }
     }
     else if (representation == 1)
     {
         if (p2 == 16 && p3 == 16)
         {
             RealPrecision = 322;//Precision.FIXED_32;
             return "FIXED_32";
         }
         else if (p2 == 32 && p3 == 32)
         {
             RealPrecision = 642;//Precision.FIXED_64;
             return "FIXED_64";
         }
         else
         {
             //Debug.Assert(false, "unsupported combination");
         }
     }
     else
     {
         //Debug.Assert(false, "unsupported representation");
     }
     return ">>>?<<<";
 }
Example #10
0
 string VDCType(Command c)
 {
     VDCtype = BinaryUtil.makeInt(c, IntPrecision);
     return _VDCtype;
 }
Example #11
0
 public static int makeSignedInt16(Command c)
 {
     return ((short)(c.ParamGet(c.CurrentArg++) << 8) + c.ParamGet(c.CurrentArg++));
     short x = BitConverter.ToInt16(c.Params, c.CurrentArg);
     c.CurrentArg += 2;
     return x;
 }
Example #12
0
 public static string getString(Command cmd)
 {
     return getString(cmd, false);
 }
Example #13
0
        public static double makeVdc(Command c, int VDCtype, CGMImage.VDCRealPrecisionType RealPrecision, int IntPrecision)
        {
            if (VDCtype == 1)//==real
            {
                if (RealPrecision == CGMImage.VDCRealPrecisionType.FLOATING_POINT_32BIT)
                {
                    return makeFloatingPoint32(c);
                }
                if (RealPrecision == CGMImage.VDCRealPrecisionType.FIXED_POINT_32BIT)
                {
                    return makeFixedPoint32(c);
                }
                if (RealPrecision == CGMImage.VDCRealPrecisionType.FIXED_POINT_64BIT)
                {
                    return makeFixedPoint64(c);
                }

                if (RealPrecision == CGMImage.VDCRealPrecisionType.FLOATING_POINT_64BIT)
                {
                    return makeFloatingPoint64(c);
                }

                //unsupported("unsupported precision " + precision);
                return makeFixedPoint32(c);
            }

            // defaults to integer
            // if (VDCType.getType().equals(VDCType.Type.INTEGER))
            {
                int precision = IntPrecision;
                if (precision == 16)
                {
                    return makeSignedInt16(c);
                }
                if (precision == 24)
                {
                    return makeSignedInt24(c);
                }
                if (precision == 32)
                {
                    return makeSignedInt32(c);
                }

                //unsupported("unsupported precision " + precision);
                return makeSignedInt16(c);
            }
        }
Example #14
0
 public static int makeUInt32(Command c)
 {
     return (char)(c.ParamGet(c.CurrentArg++) << 24) + (char)(c.ParamGet(c.CurrentArg++) << 16) + (char)(c.ParamGet(c.CurrentArg++) << 8) + (char)c.ParamGet(c.CurrentArg++);
 }
Example #15
0
 public static int makeUInt16(Command c)
 {
     ushort us = (ushort)((c.ParamGet(c.CurrentArg++) << 8) + c.ParamGet(c.CurrentArg++));
     return us;
     ushort x = BitConverter.ToUInt16(c.Params, c.CurrentArg);
     c.CurrentArg += 2;
     return x;
 }
Example #16
0
 public static int makeSignedInt8(Command c)
 {
     return c.ParamGet(c.CurrentArg++);
 }
Example #17
0
 public static int makeSignedInt32(Command c)
 {
     return (c.ParamGet(c.CurrentArg++) << 24) + (c.ParamGet(c.CurrentArg++) << 16) + (c.ParamGet(c.CurrentArg++) << 8) + c.ParamGet(c.CurrentArg++);
 }
Example #18
0
 public CGMFontList(Command c)
 {
     fonts = getFontList(c);
 }
Example #19
0
 public static int makeInt(Command c, int IntPrecision)
 {
     if (IntPrecision == 8)
     {
         return makeSignedInt8(c);
     }
     if (IntPrecision == 16)
     {
         return makeSignedInt16(c);
     }
     if (IntPrecision == 24)
     {
         makeSignedInt24(c);
     }
     if (IntPrecision == 32)
     {
         makeSignedInt32(c);
     }
     return 0;
 }
Example #20
0
        public string _VDCRealPrecisionType(Command c)
        {
            int p1 = BinaryUtil.makeInt(c, IntPrecision);
            int p2 = BinaryUtil.makeInt(c, IntPrecision);
            int p3 = BinaryUtil.makeInt(c, IntPrecision);

            if (p1 == 0)
            {
                if (p2 == 9 && p3 == 23)
                {
                    VDCRealType = VDCRealPrecisionType.FLOATING_POINT_32BIT;
                }
                else if (p2 == 12 && p3 == 52)
                {
                    VDCRealType = VDCRealPrecisionType.FLOATING_POINT_64BIT;
                }
                else
                {
                    // use default
                    //unsupported("unsupported real precision");
                    VDCRealType = VDCRealPrecisionType.FIXED_POINT_32BIT;
                }
            }
            else if (p1 == 1)
            {
                if (p2 == 16 && p3 == 16)
                {
                    VDCRealType = VDCRealPrecisionType.FIXED_POINT_32BIT;
                }
                else if (p2 == 32 && p3 == 32)
                {
                    VDCRealType = VDCRealPrecisionType.FIXED_POINT_64BIT;
                }
                else
                {
                    // use default
                    //unsupported("unsupported real precision");
                    VDCRealType = VDCRealPrecisionType.FIXED_POINT_32BIT;
                }
            }
            return VDCRealType.ToString();
        }
Example #21
0
 public static int makeByte(Command c)
 {
     return c.ParamGet(c.CurrentArg++);
 }
Example #22
0
 public static PointD makePoint(Command c, int VDCtype, CGMImage.VDCRealPrecisionType RealPrecision, int IntPrecision)
 {
     PointD pf = new PointD(
         makeVdc(c, VDCtype, RealPrecision, IntPrecision),
         makeVdc(c, VDCtype, RealPrecision, IntPrecision)
         );
     return pf;
 }
Example #23
0
 public string _VDCIntegerPrecision(Command c)
 {
     VDCIntPrecision = BinaryUtil.makeInt(c, IntPrecision);
     return VDCIntPrecision.ToString();
 }
Example #24
0
 public static byte makeChar(Command c)
 {
     return (byte)c.ParamGet(c.CurrentArg++);
 }
Example #25
0
 string ColorPrecision(Command c)
 {
     int k = BinaryUtil.makeInt(c, IntPrecision);
     return k.ToString();
 }
Example #26
0
        public CGMPolyBezier(Command c, CGMImage parent)
        {
            p1 = new List<PointD>();
            p2 = new List<PointD>();
            p3 = new List<PointD>();
            p4 = new List<PointD>();

            this.continuityIndicator = BinaryUtil.makeIndex(c, parent.IntPrecision);

            if (this.continuityIndicator == 1)
            {
                //Debug.Assert(((this.args.length - this.currentArg) / sizeOfPoint()) % 4 == 0);

                int n = ((c.ParamsLength - c.CurrentArg) / BinaryUtil.sizeOfPoint(parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision)) / 4;

                //this.p1 = new Point2D.Double[n];
                //this.p2 = new Point2D.Double[n];
                //this.p3 = new Point2D.Double[n];
                //this.p4 = new Point2D.Double[n];

                int point = 0;
                while (point < n)
                {
                    //this.p1[point] = makePoint();
                    //this.p2[point] = makePoint();
                    //this.p3[point] = makePoint();
                    //this.p4[point] = makePoint();
                    p1.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));
                    p2.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));
                    p3.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));
                    p4.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));

                    point++;
                }
            }
            else if (this.continuityIndicator == 2)
            {
                //Debug.Assert(((this.args.length - this.currentArg - 1) / sizeOfPoint()) % 3 == 0);
                //int n = ((this.args.length - this.currentArg - 1) / sizeOfPoint()) / 3;
                int n = ((c.ParamsLength - c.CurrentArg - 1) / BinaryUtil.sizeOfPoint(parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision)) / 3;

                //this.p1 = new Point2D.Double[n];
                //this.p2 = new Point2D.Double[n];
                //this.p3 = new Point2D.Double[n];
                //this.p4 = new Point2D.Double[n];

                int point = 0;
                while (point < n)
                {
                    if (point == 0)
                    {
                        this.p1.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));
                    }
                    else
                    {
                        this.p1.Add(this.p4[point - 1]);
                    }
                    p2.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));
                    p3.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));
                    p4.Add(BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.VDCIntPrecision));

                    //this.p2[point] = makePoint();
                    //this.p3[point] = makePoint();
                    //this.p4[point] = makePoint();
                    point++;
                }
            }
            //else
            //    unsupported("unsupported continuity indicator " + this.continuityIndicator);
        }
Example #27
0
 string _IntPrecision(Command c)
 {
     IntPrecision = BinaryUtil.makeSignedInt16(c);
     return IntPrecision.ToString();
 }
Example #28
0
 Command FC(Command c)
 {
     byte[] be = BinaryUtil.ExtractStream(c.Parameters);
     TraceLoading = string.Format("{0}\r\n{1}-{2}", TraceLoading, c.ElementID, c.ElementClass);
     Console.WriteLine(">> {1}-{0}", c.ElementID, c.ElementClass);
     c.Parameters.Seek(0, System.IO.SeekOrigin.Begin);
     switch (c.ElementClass)
     {
         case CGMEnumerations.CONTROL_ELEMENTS:
             {
                 if (c.ElementID == (int)CGMEnumerations.ControlElement.VDC_REAL_PRECISION)//beginmf
                 {
                     _VDCRealPrecisionType(c);
                 }
                 if (c.ElementID == (int)CGMEnumerations.ControlElement.VDC_INTEGER_PRECISION)//beginmf
                 {
                     _VDCIntegerPrecision(c);
                 }
             } break;
         case CGMEnumerations.ATTRIBUTE_ELEMENTS:
             {
                 if (c.ElementID == CGMEnumerations.RESTRICTED_TEXT_TYPE)//beginmf
                 {
                     RestrictedTextType = CGMRestrictedText.MakeType(c, this);
                     structuresFocused.Add(new CGMRestrictedTextType(RestrictedTextType));
                 }
             } break;
         case CGMEnumerations.DELIMITER_ELEMENTS:
             {
                 if (c.ElementID == CGMEnumerations.BEGIN_METAFILE)//beginmf
                 {
                     CGMHeader = BinaryUtil.getString(c);
                     byte[] strx = BinaryUtil.GetStringASCII(CGMHeader);
                     c.ClearParameters();
                     c.Parameters.Write(strx, 0, strx.Length);
                     Console.WriteLine("Begin Metafile: {0}", CGMHeader);
                 }
                 if (c.ElementID == CGMEnumerations.END_METAFILE)
                 {
                     Console.WriteLine("End Metafile.");
                 }
             } break;
         case CGMEnumerations.PICTURE_DESCRIPTOR_ELEMENTS://2
             {
                 if (c.ElementID == CGMEnumerations.SCALING_MODE)
                 {
                     this.ScalingMode = new CGMScalingMode(c, this);
                 }
                 if (c.ElementID == CGMEnumerations.VDC_EXTENT)
                 {
                     this.VDCextent = new VDCExtent(c, this);
                 }
             } break;
         case CGMEnumerations.GRAPHICAL_PRIMITIVE_ELEMENTS://4
             {
                 if (c.ElementID == CGMEnumerations.POLYBEZIER)
                 {
                     CGMPolyBezier pll = new CGMPolyBezier(c, this);
                     structuresFocused.Add(pll);
                 }
                 if (c.ElementID == CGMEnumerations.POLYLINE)
                 {
                     CGMPolyLine pll = new CGMPolyLine(c, this);
                     structuresFocused.Add(pll);
                 }
                 if (c.ElementID == CGMEnumerations.RESTRICTED_TEXT)
                 {
                     //string metf = RestictedText(c);
                     CGMRestrictedText rst = new CGMRestrictedText(c, this);
                     structuresFocused.Add(rst);
                     //Console.WriteLine("RESTRICTED_TEXT: {0}", metf);
                 }
             } break;
         case CGMEnumerations.METAFILE_DESCRIPTOR_ELEMENTS://1
             {
                 if (c.ElementID == CGMEnumerations.MAXIMUM_VDC_EXTENT)
                 {
                     VDCExtent vdc = new VDCExtent(c, this);
                 }
                 if (c.ElementID == CGMEnumerations.METAFILE_VERSION)//mfversion
                 {
                     CGMVersion = (int)BinaryUtil.makeUInt16(c);
                     Console.WriteLine("Metafile Version: {0}", CGMVersion);
                 }
                 if (c.ElementID == CGMEnumerations.METAFILE_DESCRIPTION)//mfdesc
                 {
                     CGMDescription = BinaryUtil.getString(c);
                     Console.WriteLine("Metafile Desc: {0}", CGMDescription);
                 }
                 if (c.ElementID == CGMEnumerations.FONT_LIST)//mfdesc
                 {
                     CGMFontList fl = new CGMFontList(c);
                     structuresFocused.Add(fl);
                     Console.WriteLine("Font List: {0}", fl.fonts);
                 }
                 if (c.ElementID == CGMEnumerations.INTEGER_PRECISION)
                 {
                     string metf = _IntPrecision(c);
                     Console.WriteLine("INTEGER_PRECISION: {0}", metf);
                 }
                 if (c.ElementID == CGMEnumerations.REAL_PRECISION)
                 {
                     string metf = _RealPrecision(c);
                     Console.WriteLine("REAL_PRECISION: {0}", metf);
                 }
                 if (c.ElementID == CGMEnumerations.VDC_TYPE)
                 {
                     string metf = VDCType(c);
                     Console.WriteLine("VDCtype: {0}", metf);
                 }
                 if (c.ElementID == CGMEnumerations.COLOUR_PRECISION)
                 {
                     string metf = ColorPrecision(c);
                     Console.WriteLine("COLOUR_PRECISION: {0}", metf);
                 }
             } break;
     }
     return c;
 }
Example #29
0
 public VDCExtent(Command c, CGMImage parent)
 {
     //c.CurrentArg+=3;
     this.lowerLeftCorner = BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.IntPrecision);
     this.upperRightCorner = BinaryUtil.makePoint(c, parent.VDCtype, parent.VDCRealType, parent.IntPrecision);
 }
Example #30
0
 public static double makeFloatingPoint64(Command c)
 {
     byte[] bytes = new byte[8];
     for (int i = 7; i >= 0; i--)
     {
         bytes[i] = (byte)makeChar(c);
     }
     return BitConverter.ToDouble(bytes, 0);
 }