コード例 #1
0
        public void init(InputMeta meta)
        {
            height = Math.Abs(meta.readShort());
            meta.skip(2);
            angle = (float)(meta.readShort() / 1800.0 * Math.PI);
            meta.skip(2);
            bold      = (meta.readShort() >= BOLDTHRESHOLD ? MARKER_BOLD : 0);
            italic    = (meta.readByte() != 0 ? MARKER_ITALIC : 0);
            underline = (meta.readByte() != 0);
            strikeout = (meta.readByte() != 0);
            charset   = meta.readByte();
            meta.skip(3);
            pitchAndFamily = meta.readByte();
            byte[] name = new byte[nameSize];
            int    k;

            for (k = 0; k < nameSize; ++k)
            {
                int c = meta.readByte();
                if (c == 0)
                {
                    break;
                }
                name[k] = (byte)c;
            }
            try {
                faceName = System.Text.Encoding.GetEncoding("windows-1252").GetString(name, 0, k);
            }
            catch (Exception e) {
                e.GetType();
                faceName = System.Text.ASCIIEncoding.ASCII.GetString(name, 0, k);
            }
            faceName = faceName.ToLower();
        }
コード例 #2
0
ファイル: MetaDo.cs プロジェクト: aakkssqq/CreatePDFCSharp
        public void readAll()
        {
            if (meta.readInt() != unchecked ((int)0x9AC6CDD7))
            {
                throw new DocumentException("Not a placeable windows metafile");
            }
            meta.readWord();
            left           = meta.readShort();
            top            = meta.readShort();
            right          = meta.readShort();
            bottom         = meta.readShort();
            inch           = meta.readWord();
            state.ScalingX = (float)(right - left) / (float)inch * 72f;
            state.ScalingY = (float)(bottom - top) / (float)inch * 72f;
            state.OffsetWx = left;
            state.OffsetWy = top;
            state.ExtentWx = right - left;
            state.ExtentWy = bottom - top;
            meta.readInt();
            meta.readWord();
            meta.skip(18);

            int tsize;
            int function;

            cb.LineCap  = 1;
            cb.LineJoin = 1;
            for (;;)
            {
                int lenMarker = meta.Length;
                tsize = meta.readInt();
                if (tsize < 3)
                {
                    break;
                }
                function = meta.readWord();
                switch (function)
                {
                case 0:
                    break;

                case META_CREATEPALETTE:
                case META_CREATEREGION:
                case META_DIBCREATEPATTERNBRUSH:
                    state.addMetaObject(new MetaObject());
                    break;

                case META_CREATEPENINDIRECT:
                {
                    MetaPen pen = new MetaPen();
                    pen.init(meta);
                    state.addMetaObject(pen);
                    break;
                }

                case META_CREATEBRUSHINDIRECT:
                {
                    MetaBrush brush = new MetaBrush();
                    brush.init(meta);
                    state.addMetaObject(brush);
                    break;
                }

                case META_CREATEFONTINDIRECT:
                {
                    MetaFont font = new MetaFont();
                    font.init(meta);
                    state.addMetaObject(font);
                    break;
                }

                case META_SELECTOBJECT:
                {
                    int idx = meta.readWord();
                    state.selectMetaObject(idx, cb);
                    break;
                }

                case META_DELETEOBJECT:
                {
                    int idx = meta.readWord();
                    state.deleteMetaObject(idx);
                    break;
                }

                case META_SAVEDC:
                    state.saveState(cb);
                    break;

                case META_RESTOREDC:
                {
                    int idx = meta.readShort();
                    state.restoreState(idx, cb);
                    break;
                }

                case META_SETWINDOWORG:
                    state.OffsetWy = meta.readShort();
                    state.OffsetWx = meta.readShort();
                    break;

                case META_SETWINDOWEXT:
                    state.ExtentWy = meta.readShort();
                    state.ExtentWx = meta.readShort();
                    break;

                case META_MOVETO:
                {
                    int   y = meta.readShort();
                    Point p = new Point(meta.readShort(), y);
                    state.CurrentPoint = p;
                    break;
                }

                case META_LINETO:
                {
                    int   y = meta.readShort();
                    int   x = meta.readShort();
                    Point p = state.CurrentPoint;
                    cb.moveTo(state.transformX(p.X), state.transformY(p.Y));
                    cb.lineTo(state.transformX(x), state.transformY(y));
                    cb.stroke();
                    state.CurrentPoint = new Point(x, y);
                    break;
                }

                case META_POLYLINE:
                {
                    state.LineJoinPolygon = cb;
                    int len = meta.readWord();
                    int x   = meta.readShort();
                    int y   = meta.readShort();
                    cb.moveTo(state.transformX(x), state.transformY(y));
                    for (int k = 1; k < len; ++k)
                    {
                        x = meta.readShort();
                        y = meta.readShort();
                        cb.lineTo(state.transformX(x), state.transformY(y));
                    }
                    cb.stroke();
                    break;
                }

                case META_POLYGON:
                {
                    if (isNullStrokeFill(false))
                    {
                        break;
                    }
                    int len = meta.readWord();
                    int sx  = meta.readShort();
                    int sy  = meta.readShort();
                    cb.moveTo(state.transformX(sx), state.transformY(sy));
                    for (int k = 1; k < len; ++k)
                    {
                        int x = meta.readShort();
                        int y = meta.readShort();
                        cb.lineTo(state.transformX(x), state.transformY(y));
                    }
                    cb.lineTo(state.transformX(sx), state.transformY(sy));
                    strokeAndFill();
                    break;
                }

                case META_POLYPOLYGON:
                {
                    if (isNullStrokeFill(false))
                    {
                        break;
                    }
                    int   numPoly = meta.readWord();
                    int[] lens    = new int[numPoly];
                    for (int k = 0; k < lens.Length; ++k)
                    {
                        lens[k] = meta.readWord();
                    }
                    for (int j = 0; j < lens.Length; ++j)
                    {
                        int len = lens[j];
                        int sx  = meta.readShort();
                        int sy  = meta.readShort();
                        cb.moveTo(state.transformX(sx), state.transformY(sy));
                        for (int k = 1; k < len; ++k)
                        {
                            int x = meta.readShort();
                            int y = meta.readShort();
                            cb.lineTo(state.transformX(x), state.transformY(y));
                        }
                        cb.lineTo(state.transformX(sx), state.transformY(sy));
                    }
                    strokeAndFill();
                    break;
                }

                case META_ELLIPSE:
                {
                    if (isNullStrokeFill(state.LineNeutral))
                    {
                        break;
                    }
                    int b = meta.readShort();
                    int r = meta.readShort();
                    int t = meta.readShort();
                    int l = meta.readShort();
                    cb.arc(state.transformX(l), state.transformY(b), state.transformX(r), state.transformY(t), 0, 360);
                    strokeAndFill();
                    break;
                }

                case META_ARC:
                {
                    if (isNullStrokeFill(state.LineNeutral))
                    {
                        break;
                    }
                    float yend   = state.transformY(meta.readShort());
                    float xend   = state.transformX(meta.readShort());
                    float ystart = state.transformY(meta.readShort());
                    float xstart = state.transformX(meta.readShort());
                    float b      = state.transformY(meta.readShort());
                    float r      = state.transformX(meta.readShort());
                    float t      = state.transformY(meta.readShort());
                    float l      = state.transformX(meta.readShort());
                    float cx     = (r + l) / 2;
                    float cy     = (t + b) / 2;
                    float arc1   = getArc(cx, cy, xstart, ystart);
                    float arc2   = getArc(cx, cy, xend, yend);
                    arc2 -= arc1;
                    if (arc2 <= 0)
                    {
                        arc2 += 360;
                    }
                    cb.arc(l, b, r, t, arc1, arc2);
                    cb.stroke();
                    break;
                }

                case META_PIE:
                {
                    if (isNullStrokeFill(state.LineNeutral))
                    {
                        break;
                    }
                    float yend   = state.transformY(meta.readShort());
                    float xend   = state.transformX(meta.readShort());
                    float ystart = state.transformY(meta.readShort());
                    float xstart = state.transformX(meta.readShort());
                    float b      = state.transformY(meta.readShort());
                    float r      = state.transformX(meta.readShort());
                    float t      = state.transformY(meta.readShort());
                    float l      = state.transformX(meta.readShort());
                    float cx     = (r + l) / 2;
                    float cy     = (t + b) / 2;
                    float arc1   = getArc(cx, cy, xstart, ystart);
                    float arc2   = getArc(cx, cy, xend, yend);
                    arc2 -= arc1;
                    if (arc2 <= 0)
                    {
                        arc2 += 360;
                    }
                    ArrayList ar = PdfContentByte.bezierArc(l, b, r, t, arc1, arc2);
                    if (ar.Count == 0)
                    {
                        break;
                    }
                    float[] pt = (float [])ar[0];
                    cb.moveTo(cx, cy);
                    cb.lineTo(pt[0], pt[1]);
                    for (int k = 0; k < ar.Count; ++k)
                    {
                        pt = (float [])ar[k];
                        cb.curveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]);
                    }
                    cb.lineTo(cx, cy);
                    strokeAndFill();
                    break;
                }

                case META_CHORD:
                {
                    if (isNullStrokeFill(state.LineNeutral))
                    {
                        break;
                    }
                    float yend   = state.transformY(meta.readShort());
                    float xend   = state.transformX(meta.readShort());
                    float ystart = state.transformY(meta.readShort());
                    float xstart = state.transformX(meta.readShort());
                    float b      = state.transformY(meta.readShort());
                    float r      = state.transformX(meta.readShort());
                    float t      = state.transformY(meta.readShort());
                    float l      = state.transformX(meta.readShort());
                    float cx     = (r + l) / 2;
                    float cy     = (t + b) / 2;
                    float arc1   = getArc(cx, cy, xstart, ystart);
                    float arc2   = getArc(cx, cy, xend, yend);
                    arc2 -= arc1;
                    if (arc2 <= 0)
                    {
                        arc2 += 360;
                    }
                    ArrayList ar = PdfContentByte.bezierArc(l, b, r, t, arc1, arc2);
                    if (ar.Count == 0)
                    {
                        break;
                    }
                    float[] pt = (float [])ar[0];
                    cx = pt[0];
                    cy = pt[1];
                    cb.moveTo(cx, cy);
                    for (int k = 0; k < ar.Count; ++k)
                    {
                        pt = (float [])ar[k];
                        cb.curveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]);
                    }
                    cb.lineTo(cx, cy);
                    strokeAndFill();
                    break;
                }

                case META_RECTANGLE:
                {
                    if (isNullStrokeFill(true))
                    {
                        break;
                    }
                    float b = state.transformY(meta.readShort());
                    float r = state.transformX(meta.readShort());
                    float t = state.transformY(meta.readShort());
                    float l = state.transformX(meta.readShort());
                    cb.rectangle(l, b, r - l, t - b);
                    strokeAndFill();
                    break;
                }

                case META_INTERSECTCLIPRECT:
                {
                    float b = state.transformY(meta.readShort());
                    float r = state.transformX(meta.readShort());
                    float t = state.transformY(meta.readShort());
                    float l = state.transformX(meta.readShort());
                    cb.rectangle(l, b, r - l, t - b);
                    cb.eoClip();
                    cb.newPath();
                    break;
                }

                case META_EXTTEXTOUT:
                {
                    int y     = meta.readShort();
                    int x     = meta.readShort();
                    int count = meta.readWord();
                    int flag  = meta.readWord();
                    int x1    = 0;
                    int y1    = 0;
                    int x2    = 0;
                    int y2    = 0;
                    if ((flag & (MetaFont.ETO_CLIPPED | MetaFont.ETO_OPAQUE)) != 0)
                    {
                        x1 = meta.readShort();
                        y1 = meta.readShort();
                        x2 = meta.readShort();
                        y2 = meta.readShort();
                    }
                    byte[] text = new byte[count];
                    int    k;
                    for (k = 0; k < count; ++k)
                    {
                        byte c = (byte)meta.readByte();
                        if (c == 0)
                        {
                            break;
                        }
                        text[k] = c;
                    }
                    string s;
                    try {
                        s = System.Text.Encoding.GetEncoding("windows-1252").GetString(text, 0, k);
                    }
                    catch (Exception e) {
                        e.GetType();
                        s = System.Text.ASCIIEncoding.ASCII.GetString(text, 0, k);
                    }
                    outputText(x, y, flag, x1, y1, x2, y2, s);
                    break;
                }

                case META_TEXTOUT:
                {
                    int    count = meta.readWord();
                    byte[] text  = new byte[count];
                    int    k;
                    for (k = 0; k < count; ++k)
                    {
                        byte c = (byte)meta.readByte();
                        if (c == 0)
                        {
                            break;
                        }
                        text[k] = c;
                    }
                    string s;
                    try {
                        s = System.Text.Encoding.GetEncoding("windows-1252").GetString(text, 0, k);
                    }
                    catch (Exception e) {
                        e.GetType();
                        s = System.Text.ASCIIEncoding.ASCII.GetString(text, 0, k);
                    }
                    count = (count + 1) & 0xfffe;
                    meta.skip(count - k);
                    int y = meta.readShort();
                    int x = meta.readShort();
                    outputText(x, y, 0, 0, 0, 0, 0, s);
                    break;
                }

                case META_SETBKCOLOR:
                    state.CurrentBackgroundColor = meta.readColor();
                    break;

                case META_SETTEXTCOLOR:
                    state.CurrentTextColor = meta.readColor();
                    break;

                case META_SETTEXTALIGN:
                    state.TextAlign = meta.readWord();
                    break;

                case META_SETBKMODE:
                    state.BackgroundMode = meta.readWord();
                    break;

                case META_SETPOLYFILLMODE:
                    state.PolyFillMode = meta.readWord();
                    break;

                case META_SETPIXEL:
                {
                    Color color = meta.readColor();
                    int   y     = meta.readShort();
                    int   x     = meta.readShort();
                    cb.saveState();
                    cb.ColorFill = color;
                    cb.rectangle(state.transformX(x), state.transformY(y), .2f, .2f);
                    cb.fill();
                    cb.restoreState();
                    break;
                }
                }
                meta.skip((tsize * 2) - (meta.Length - lenMarker));
            }
        }