wire up retrieving glyph bounding box from a truetype font when retrieving a displacement vector. this is not used currently

This commit is contained in:
Eliot Jones
2018-03-31 13:27:27 +01:00
parent 0ae20c51f3
commit ea55256e78
3 changed files with 41 additions and 5 deletions

View File

@@ -13,7 +13,7 @@
internal class TrueTypeSimpleFont : IFont
{
private static readonly TransformationMatrix FontMatrix =
TransformationMatrix.FromValues(1/1000m, 0, 0, 1/1000m, 0, 0);
TransformationMatrix.FromValues(1 / 1000m, 0, 0, 1 / 1000m, 0, 0);
private readonly int firstCharacterCode;
private readonly int lastCharacterCode;
private readonly decimal[] widths;
@@ -33,7 +33,7 @@
public TrueTypeSimpleFont(NameToken name, int firstCharacterCode, int lastCharacterCode, decimal[] widths,
FontDescriptor descriptor,
[CanBeNull] CMap toUnicodeCMap,
[CanBeNull] Encoding encoding,
[CanBeNull] Encoding encoding,
[CanBeNull]TrueTypeFont font)
{
this.firstCharacterCode = firstCharacterCode;
@@ -88,13 +88,15 @@
{
var tx = GetWidth(characterCode);
var box = GetBoundingBox(characterCode);
return new PdfVector(tx / 1000m, 0);
}
public decimal GetWidth(int characterCode)
{
var index = characterCode - firstCharacterCode;
if (index < 0 || index >= widths.Length)
{
return descriptor.MissingWidth;
@@ -105,7 +107,19 @@
public PdfRectangle GetBoundingBox(int characterCode)
{
throw new System.NotImplementedException();
if (font?.CMapTable == null)
{
return descriptor.BoundingBox;
}
if (!font.CMapTable.TryGetGlyphIndex(characterCode, out var index))
{
return descriptor.BoundingBox;
}
var glyph = font.GlyphTable.Glyphs[index];
return glyph?.GlyphBounds ?? descriptor.BoundingBox;
}
public TransformationMatrix GetFontMatrix()

View File

@@ -34,7 +34,7 @@
public int CharacterCodeToGlyphIndex(int characterCode)
{
if (characterCode < GlyphMappingLength || characterCode >= GlyphMappingLength)
if (characterCode < 0 || characterCode >= GlyphMappingLength)
{
return 0;
}

View File

@@ -21,6 +21,28 @@
DirectoryTable = directoryTable;
}
public bool TryGetGlyphIndex(int characterCode, out int glyphIndex)
{
glyphIndex = 0;
if (subTables.Count == 0)
{
return false;
}
foreach (var subTable in subTables)
{
glyphIndex = subTable.CharacterCodeToGlyphIndex(characterCode);
if (glyphIndex != 0)
{
return true;
}
}
return false;
}
public static CMapTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister tableRegister)
{
data.Seek(table.Offset);