public void TestType3FontWidth() { String inFile = "type3font_text.pdf"; LineSegment origLineSegment = new LineSegment(new Vector(20.3246f, 769.4974f, 1.0f), new Vector(151.22923f, 769.4974f, 1.0f)); PdfReader reader = TestResourceUtils.GetResourceAsPdfReader(TEST_RESOURCES_PATH, inFile); TextPositionRenderListener renderListener = new TextPositionRenderListener(); PdfContentStreamProcessor processor = new PdfContentStreamProcessor(renderListener); PdfDictionary pageDic = reader.GetPageN(FIRST_PAGE); PdfDictionary resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES); processor.ProcessContent(ContentByteUtils.GetContentBytesForPage(reader, FIRST_PAGE), resourcesDic); Assert.AreEqual(renderListener.LineSegments[FIRST_ELEMENT_INDEX].GetStartPoint()[FIRST_ELEMENT_INDEX], origLineSegment.GetStartPoint()[FIRST_ELEMENT_INDEX], 1/2f); Assert.AreEqual(renderListener.LineSegments[FIRST_ELEMENT_INDEX].GetEndPoint()[FIRST_ELEMENT_INDEX], origLineSegment.GetEndPoint()[FIRST_ELEMENT_INDEX], 1/2f); }
/// <summary> /// Represents a chunk of text, it's orientation, and location relative to the orientation vector /// </summary> /// <param name="txt"></param> /// <param name="startLoc"></param> /// <param name="endLoc"></param> /// <param name="charSpaceWidth"></param> public TextChunkEx(string txt, iTextSharp.text.pdf.parser.Vector startLoc, iTextSharp.text.pdf.parser.Vector endLoc, float charSpaceWidth, iTextSharp.text.pdf.parser.LineSegment ascentLine, iTextSharp.text.pdf.parser.LineSegment decentLine) { m_text = txt; m_startLocation = startLoc; m_endLocation = endLoc; m_charSpaceWidth = charSpaceWidth; AscentLine = ascentLine; DecentLine = decentLine; m_orientationVector = m_endLocation.Subtract(m_startLocation); if (m_orientationVector.Length == 0) m_orientationVector = new Vector(1, 0, 0); m_orientationVector = m_orientationVector.Normalize(); m_orientationMagnitude = (int)(Math.Atan2(m_orientationVector[iTextSharp.text.pdf.parser.Vector.I2], m_orientationVector[iTextSharp.text.pdf.parser.Vector.I1]) * 1000); // see http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html // the two vectors we are crossing are in the same plane, so the result will be purely // in the z-axis (out of plane) direction, so we just take the I3 component of the result iTextSharp.text.pdf.parser.Vector origin = new iTextSharp.text.pdf.parser.Vector(0, 0, 1); m_distPerpendicular = (int)(m_startLocation.Subtract(origin)).Cross(m_orientationVector)[iTextSharp.text.pdf.parser.Vector.I3]; m_distParallelStart = m_orientationVector.Dot(m_startLocation); m_distParallelEnd = m_orientationVector.Dot(m_endLocation); }
/** * * @param height the height, in text space * @return the height in user space * @since 5.3.3 */ private float ConvertHeightFromTextSpaceToUserSpace(float height) { LineSegment textSpace = new LineSegment(new Vector(0, 0, 1), new Vector(0, height, 1)); LineSegment userSpace = textSpace.TransformBy(textToUserSpaceTransformMatrix); return userSpace.GetLength(); }
/** * @return The width, in user space units, of a single space character in the current font */ public float GetSingleSpaceWidth() { LineSegment textSpace = new LineSegment(new Vector(0, 0, 1), new Vector(GetUnscaledFontSpaceWidth(), 0, 1)); LineSegment userSpace = textSpace.TransformBy(textToUserSpaceTransformMatrix); return userSpace.GetLength(); }
public ITextChunkLocation CreateLocation(TextRenderInfo renderInfo, LineSegment baseline) { return(new TextChunkLocationDefaultImp(baseline.GetStartPoint(), baseline.GetEndPoint(), renderInfo.GetSingleSpaceWidth())); }