Example #1
0
        /// <summary>
        /// Adjust horizonal text position
        /// </summary>
        public void AdjustPosition(double adjustment, FontState fontState)
        {
            var m1 = new Matrix(fontState.TextMatrix.M11, fontState.TextMatrix.M12, fontState.TextMatrix.M21, fontState.TextMatrix.M22, 0, 0);
            var p2 = new Point(adjustment, 0) * m1;

            var m = fontState.TextMatrix;

            m.Translate(-p2.X / 1000 * fontState.FontSize, 0);
            fontState.TextMatrix = m;
        }
Example #2
0
        /// <summary>
        /// Convert a given text to graphic paths
        /// </summary>
        public List <GraphicPath> Vectorize(string text, GraphicsState currentGraphicsState, FontState fontState)
        {
            this.currentGraphicsState = currentGraphicsState;
            this.fontState            = fontState;

            List <GraphicPath> pdfGraphicsPaths = new List <GraphicPath>();

            var typeFace = fontState.FontDescriptor.GetTypeFace();

            FormattedText formattedText = new FormattedText(
                text,
                CultureInfo.InvariantCulture,
                FlowDirection.LeftToRight,
                typeFace,
                fontState.FontSize,
                Brushes.Black,
                96);

            var fontMirror = new Matrix(1, 0, 0, -1, 0, formattedText.Baseline);

            fontTransformation = fontMirror * fontState.TextMatrix * currentGraphicsState.Mirror;

            var myPathGeometry = formattedText.BuildGeometry(new Point(0, 0));

            ConvertToGraphicPath(pdfGraphicsPaths, myPathGeometry);

            var m  = new Matrix(fontState.TextMatrix.M11, fontState.TextMatrix.M12, fontState.TextMatrix.M21, fontState.TextMatrix.M22, 0, 0);
            var p2 = new Point(formattedText.WidthIncludingTrailingWhitespace, 0) * m;

            var fsm = fontState.TextMatrix;

            fsm.Translate(p2.X, 0);
            fontState.TextMatrix = fsm;

            return(pdfGraphicsPaths);
        }