コード例 #1
0
        public static void Run(Type1BuildCharContext context)
        {
            var x = context.Stack.PopBottom();
            var y = context.Stack.PopBottom();

            //context.CurrentPosition = new PdfPoint(x, y);
            // TODO: need to investigate why odd behavior when the current point is actualy set.
            context.Stack.Clear();
        }
コード例 #2
0
ファイル: DivCommand.cs プロジェクト: zyj0021/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var first  = context.Stack.PopTop();
            var second = context.Stack.PopTop();

            var result = second / first;

            context.Stack.Push(result);
        }
コード例 #3
0
        public static void Run(Type1BuildCharContext context)
        {
            var x = context.Stack.PopBottom();
            var y = context.Stack.PopBottom();

            context.CurrentPosition = new PdfPoint(x, y);

            context.Stack.Clear();
        }
コード例 #4
0
        public static void Run(Type1BuildCharContext context)
        {
            var x  = context.Stack.PopBottom();
            var dx = context.Stack.PopBottom();

            // Ignored

            context.Stack.Clear();
        }
コード例 #5
0
        public static void Run(Type1BuildCharContext context)
        {
            var deltaX = context.Stack.PopBottom();
            var x      = context.CurrentPosition.X + deltaX;

            context.Path.LineTo(x, context.CurrentPosition.Y);
            context.CurrentPosition = new PdfPoint(x, context.CurrentPosition.Y);

            context.Stack.Clear();
        }
コード例 #6
0
ファイル: VLineToCommand.cs プロジェクト: rbanks54/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var deltaY = context.Stack.PopBottom();
            var y      = context.CurrentPosition.Y + deltaY;

            context.Path.LineTo(context.CurrentPosition.X, y);
            context.CurrentPosition = new PdfPoint(context.CurrentPosition.X, y);

            context.Stack.Clear();
        }
コード例 #7
0
ファイル: HsbwCommand.cs プロジェクト: zyj0021/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var leftSidebearingPointX = context.Stack.PopBottom();
            var characterWidthVectorX = context.Stack.PopBottom();

            context.LeftSideBearingX = leftSidebearingPointX;
            context.WidthX           = characterWidthVectorX;

            context.CurrentPosition = new PdfPoint(leftSidebearingPointX, 0);

            context.Stack.Clear();
        }
コード例 #8
0
        public static void Run(Type1BuildCharContext context)
        {
            var index = (int)context.Stack.PopTop();

            var subroutine = context.Subroutines[index];

            foreach (var command in subroutine.Commands)
            {
                command.Match(x => context.Stack.Push(x),
                              x => x.Run(context));
            }
        }
コード例 #9
0
ファイル: SeacCommand.cs プロジェクト: Omsaaf/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var accentLeftSidebearingX = context.Stack.PopBottom();
            var accentOriginX          = context.Stack.PopBottom();
            var accentOriginY          = context.Stack.PopBottom();
            var baseCharacterCode      = context.Stack.PopBottom();
            var accentCharacterCode    = context.Stack.PopBottom();

            var baseCharacter   = context.GetCharacter((int)baseCharacterCode);
            var accentCharacter = context.GetCharacter((int)accentCharacterCode);

            // TODO: full seac implementation.
            context.SetPath(baseCharacter);

            context.Stack.Clear();
        }
コード例 #10
0
ファイル: CallSubrCommand.cs プロジェクト: xtuzy/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var index = (int)context.Stack.PopTop();

            var subroutine = context.Subroutines[index];

            foreach (var command in subroutine.Commands)
            {
                if (command.TryGetFirst(out var num))
                {
                    context.Stack.Push(num);
                }
                else if (command.TryGetSecond(out var lazyCommand))
                {
                    lazyCommand.Run(context);
                }
            }
        }
コード例 #11
0
        public static void Run(Type1BuildCharContext context)
        {
            var deltaX = context.Stack.PopBottom();
            var deltaY = context.Stack.PopBottom();

            if (context.IsFlexing)
            {
            }
            else
            {
                var x = context.CurrentPosition.X + deltaX;
                var y = context.CurrentPosition.Y + deltaY;
                context.CurrentPosition = new PdfPoint(x, y);
                context.Path.MoveTo(x, y);
            }

            context.Stack.Clear();
        }
コード例 #12
0
ファイル: HMoveToCommand.cs プロジェクト: rbanks54/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var x = context.Stack.PopBottom();

            var actualX = context.CurrentPosition.X + x;
            var y       = context.CurrentPosition.Y;

            if (context.IsFlexing)
            {
                // TODO: flex support
            }
            else
            {
                context.CurrentPosition = new PdfPoint(actualX, y);
                context.Path.MoveTo(actualX, y);
            }

            context.Stack.Clear();
        }
コード例 #13
0
ファイル: HMoveToCommand.cs プロジェクト: xtuzy/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var deltaX = context.Stack.PopBottom();

            if (context.IsFlexing)
            {
                // not in the Type 1 spec, but exists in some fonts
                context.AddFlexPoint(new PdfPoint(deltaX, 0));
            }
            else
            {
                var x = context.CurrentPosition.X + deltaX;
                var y = context.CurrentPosition.Y;
                context.CurrentPosition = new PdfPoint(x, y);
                context.Path.MoveTo(x, y);
            }

            context.Stack.Clear();
        }
コード例 #14
0
        public static void Run(Type1BuildCharContext context)
        {
            var accentLeftSidebearingX = context.Stack.PopBottom();
            var accentOriginX          = context.Stack.PopBottom();
            var accentOriginY          = context.Stack.PopBottom();
            var baseCharacterCode      = (int)context.Stack.PopBottom();
            var accentCharacterCode    = (int)context.Stack.PopBottom();

            // Both bchar and achar are codes that these characters are assigned in the Adobe StandardEncoding vector
            var baseCharacterName   = StandardEncoding.Instance.CodeToNameMap[baseCharacterCode];
            var accentCharacterName = StandardEncoding.Instance.CodeToNameMap[accentCharacterCode];

            var baseCharacter   = context.GetCharacter(baseCharacterName);
            var accentCharacter = context.GetCharacter(accentCharacterName);

            // TODO: full seac implementation.
            context.SetPath(baseCharacter);

            context.Stack.Clear();
        }
コード例 #15
0
ファイル: HvCurveToCommand.cs プロジェクト: zyj0021/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var dx1 = context.Stack.PopBottom();
            var dx2 = context.Stack.PopBottom();
            var dy2 = context.Stack.PopBottom();
            var dy3 = context.Stack.PopBottom();

            var x1 = context.CurrentPosition.X + dx1;
            var y1 = context.CurrentPosition.Y;

            var x2 = x1 + dx2;
            var y2 = y1 + dy2;

            var x3 = x2;
            var y3 = y2 + dy3;

            context.Path.BezierCurveTo(x1, y1, x2, y2, x3, y3);
            context.CurrentPosition = new PdfPoint(x3, y3);

            context.Stack.Clear();
        }
コード例 #16
0
ファイル: ReturnCommand.cs プロジェクト: zyj0021/PdfPig
 public static void Run(Type1BuildCharContext context)
 {
     // Do nothing
 }
コード例 #17
0
ファイル: CallOtherSubrCommand.cs プロジェクト: Omsaaf/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var index = (int)context.Stack.PopTop();

            // What it should do
            var numberOfArguments        = (int)context.Stack.PopTop();
            var otherSubroutineArguments = new List <decimal>(numberOfArguments);

            for (int j = 0; j < numberOfArguments; j++)
            {
                otherSubroutineArguments.Add(context.Stack.PopTop());
            }

            switch (index)
            {
            // Other subrs 0-2 implement flex
            case FlexEnd:
            {
                context.IsFlexing = false;
                if (context.FlexPoints.Count < 7)
                {
                    throw new NotSupportedException("There must be at least 7 flex points defined by an other subroutine.");
                }

                context.ClearFlexPoints();
                break;
            }

            case FlexBegin:
                Debug.Assert(otherSubroutineArguments.Count == 0, "Flex begin should have no arguments.");

                context.PostscriptStack.Clear();
                context.PostscriptStack.Push(context.CurrentPosition.X);
                context.PostscriptStack.Push(context.CurrentPosition.Y);
                context.IsFlexing = true;
                break;

            case FlexMiddle:
                Debug.Assert(otherSubroutineArguments.Count == 0, "Flex middle should have no arguments.");

                context.PostscriptStack.Push(context.CurrentPosition.X);
                context.PostscriptStack.Push(context.CurrentPosition.Y);
                break;

            // Other subrs 3 implements hint replacement
            case HintReplacement:
                if (otherSubroutineArguments.Count != 1)
                {
                    throw new InvalidOperationException("The hint replacement subroutine only takes a single argument.");
                }

                context.PostscriptStack.Clear();
                context.PostscriptStack.Push(otherSubroutineArguments[0]);
                break;

            default:
                // Other subrs beyond the first 4 can safely be ignored.
                context.PostscriptStack.Clear();
                for (var i = 0; i < otherSubroutineArguments.Count; i++)
                {
                    context.PostscriptStack.Push(otherSubroutineArguments[i]);
                }
                break;
            }
        }
コード例 #18
0
ファイル: CallOtherSubrCommand.cs プロジェクト: xtuzy/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var index = (int)context.Stack.PopTop();

            // What it should do
            var numberOfArguments = (int)context.Stack.PopTop();
            var otherSubroutineArguments = new List<double>(numberOfArguments);
            for (int j = 0; j < numberOfArguments; j++)
            {
                otherSubroutineArguments.Add(context.Stack.PopTop());
            }

            switch (index)
            {
                // Other subrs 0-2 implement flex
                case FlexEnd:
                    {
                        // https://github.com/apache/pdfbox/blob/2c23d8b4e3ad61852f0b6ee2b95b907eefba1fcf/fontbox/src/main/java/org/apache/fontbox/cff/Type1CharString.java#L339
                        context.IsFlexing = false;
                        if (context.FlexPoints.Count < 7)
                        {
                            throw new NotSupportedException("There must be at least 7 flex points defined by an other subroutine.");
                        }

                        // reference point is relative to start point
                        PdfPoint reference = context.FlexPoints[0];
                        reference = reference.Translate(context.CurrentPosition.X, context.CurrentPosition.Y);

                        // first point is relative to reference point
                        PdfPoint first = context.FlexPoints[1];
                        first = first.Translate(reference.X, reference.Y);

                        // make the first point relative to the start point
                        first = first.Translate(-context.CurrentPosition.X, -context.CurrentPosition.Y);

                        context.Stack.Push(first.X);
                        context.Stack.Push(first.Y);
                        context.Stack.Push(context.FlexPoints[2].X);
                        context.Stack.Push(context.FlexPoints[2].Y);
                        context.Stack.Push(context.FlexPoints[3].X);
                        context.Stack.Push(context.FlexPoints[3].Y);
                        RelativeRCurveToCommand.Run(context);

                        context.Stack.Push(context.FlexPoints[4].X);
                        context.Stack.Push(context.FlexPoints[4].Y);
                        context.Stack.Push(context.FlexPoints[5].X);
                        context.Stack.Push(context.FlexPoints[5].Y);
                        context.Stack.Push(context.FlexPoints[6].X);
                        context.Stack.Push(context.FlexPoints[6].Y);
                        RelativeRCurveToCommand.Run(context);

                        context.ClearFlexPoints();
                        break;
                    }
                case FlexBegin:
                    Debug.Assert(otherSubroutineArguments.Count == 0, "Flex begin should have no arguments.");

                    context.PostscriptStack.Clear();
                    context.PostscriptStack.Push(context.CurrentPosition.X);
                    context.PostscriptStack.Push(context.CurrentPosition.Y);
                    context.IsFlexing = true;
                    break;
                case FlexMiddle:
                    Debug.Assert(otherSubroutineArguments.Count == 0, "Flex middle should have no arguments.");

                    context.PostscriptStack.Push(context.CurrentPosition.X);
                    context.PostscriptStack.Push(context.CurrentPosition.Y);
                    break;
                // Other subrs 3 implements hint replacement
                case HintReplacement:
                    if (otherSubroutineArguments.Count != 1)
                    {
                        throw new InvalidOperationException("The hint replacement subroutine only takes a single argument.");
                    }

                    context.PostscriptStack.Clear();
                    context.PostscriptStack.Push(otherSubroutineArguments[0]);
                    break;
                default:
                    // Other subrs beyond the first 4 can safely be ignored.
                    context.PostscriptStack.Clear();
                    for (var i = 0; i < otherSubroutineArguments.Count; i++)
                    {
                        context.PostscriptStack.Push(otherSubroutineArguments[i]);
                    }
                    break;
            }
        }
コード例 #19
0
ファイル: PopCommand.cs プロジェクト: zyj0021/PdfPig
        public static void Run(Type1BuildCharContext context)
        {
            var num = context.PostscriptStack.PopTop();

            context.Stack.Push(num);
        }
コード例 #20
0
ファイル: EndCharCommand.cs プロジェクト: zyj0021/PdfPig
 public static void Run(Type1BuildCharContext context)
 {
     context.Stack.Clear();
 }
コード例 #21
0
ファイル: ClosePathCommand.cs プロジェクト: xtuzy/PdfPig
 public static void Run(Type1BuildCharContext context)
 {
     context.Path.CloseSubpath();
     context.Stack.Clear();
 }