public CharacterBoundingBox GetBoundingBox(int characterCode) { if (boundingBoxCache.TryGetValue(characterCode, out var cached)) { return(cached); } var matrix = GetFontMatrix(); var boundingBox = GetBoundingBoxInGlyphSpace(characterCode); boundingBox = matrix.Transform(boundingBox); var characterIdentifier = CMap.ConvertToCid(characterCode); var width = CidFont.GetWidthFromFont(characterIdentifier); var advanceWidth = matrix.TransformX(width); var result = new CharacterBoundingBox(boundingBox, advanceWidth); boundingBoxCache[characterCode] = result; return(result); }
public CharacterBoundingBox GetBoundingBox(int characterCode) { if (boundingBoxCache.TryGetValue(characterCode, out var cached)) { return(cached); } var fontMatrix = GetFontMatrix(); var boundingBox = GetBoundingBoxInGlyphSpace(characterCode, out var fromFont); var boundingBoxPreTransform = boundingBox.Width; if (fromFont) { boundingBox = fontMatrix.Transform(boundingBox); } else { boundingBox = DefaultTransformation.Transform(boundingBox); } decimal width; var index = characterCode - firstCharacter; if (widths != null && index >= 0 && index < widths.Length) { fromFont = false; width = widths[index]; } else if (fontProgram != null) { if (!fontProgram.TryGetBoundingAdvancedWidth(characterCode, out width)) { width = boundingBoxPreTransform; } } else { throw new InvalidOperationException($"Could not retrieve width for character code: {characterCode} in font {Name}."); } if (fromFont) { width = fontMatrix.Transform(new PdfVector(width, 0)).X; } else { width = DefaultTransformation.Transform(new PdfVector(width, 0)).X; } var result = new CharacterBoundingBox(boundingBox, width); boundingBoxCache[characterCode] = result; return(result); }
public CharacterBoundingBox GetBoundingBox(int characterCode) { if (cachedBoundingBoxes.TryGetValue(characterCode, out var box)) { return(box); } var boundingBox = GetBoundingBoxInGlyphSpace(characterCode); var matrix = fontMatrix; boundingBox = matrix.Transform(boundingBox); var width = GetWidth(characterCode, boundingBox); var result = new CharacterBoundingBox(boundingBox, width / 1000.0); cachedBoundingBoxes[characterCode] = result; return(result); }