mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-18 18:27:55 +08:00
cache bounding boxes for composite fonts
cached the bounding box for a specific character code value for type 0 (composite) fonts to improve performance.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
namespace UglyToad.PdfPig.PdfFonts.Composite
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CidFonts;
|
||||
using Cmap;
|
||||
using Core;
|
||||
@@ -16,6 +17,8 @@
|
||||
private readonly CMap ucs2CMap;
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private readonly bool isChineseJapaneseOrKorean;
|
||||
private readonly Dictionary<int, CharacterBoundingBox> boundingBoxCache
|
||||
= new Dictionary<int, CharacterBoundingBox>();
|
||||
|
||||
public NameToken Name => BaseFont;
|
||||
|
||||
@@ -84,6 +87,11 @@
|
||||
|
||||
public CharacterBoundingBox GetBoundingBox(int characterCode)
|
||||
{
|
||||
if (boundingBoxCache.TryGetValue(characterCode, out var cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
var matrix = GetFontMatrix();
|
||||
|
||||
var boundingBox = GetBoundingBoxInGlyphSpace(characterCode);
|
||||
@@ -96,7 +104,11 @@
|
||||
|
||||
var advanceWidth = matrix.TransformX(width);
|
||||
|
||||
return new CharacterBoundingBox(boundingBox, advanceWidth);
|
||||
var result = new CharacterBoundingBox(boundingBox, advanceWidth);
|
||||
|
||||
boundingBoxCache[characterCode] = result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public PdfRectangle GetBoundingBoxInGlyphSpace(int characterCode)
|
||||
|
Reference in New Issue
Block a user