mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 03:34:52 +08:00
#6 add debugging code for inspecting svgs of generated cff glyphs fix small bugs
This commit is contained in:
@@ -16,7 +16,10 @@
|
||||
[Fact]
|
||||
public void CanReadContent()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilename()))
|
||||
using (var document = PdfDocument.Open(GetFilename(), new ParsingOptions
|
||||
{
|
||||
UseLenientParsing = false
|
||||
}))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
|
||||
|
@@ -42,6 +42,8 @@
|
||||
|
||||
public PdfPoint CurrentLocation { get; set; } = new PdfPoint(0, 0);
|
||||
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
public void AddRelativeHorizontalLine(decimal dx)
|
||||
{
|
||||
AddRelativeLine(dx, 0);
|
||||
|
@@ -332,6 +332,8 @@
|
||||
|
||||
ctx.AddRelativeBezierCurve(dx1, dy1, dx2, dy2, 0, dy3);
|
||||
}
|
||||
|
||||
ctx.Stack.Clear();
|
||||
})
|
||||
},
|
||||
{ 27, new LazyType2Command("hhcurveto", ctx =>
|
||||
|
@@ -43,16 +43,69 @@
|
||||
return glyph;
|
||||
}
|
||||
|
||||
private static CharacterPath Run(CommandSequence sequence)
|
||||
public static CharacterPath Run(CommandSequence sequence)
|
||||
{
|
||||
var context = new Type2BuildCharContext();
|
||||
|
||||
var hasRunStackClearingCommand = false;
|
||||
foreach (var command in sequence.Commands)
|
||||
{
|
||||
//command.Match(x => context.Stack.Push(x),
|
||||
// x => x.Run(context));
|
||||
command.Match(x => context.Stack.Push(x),
|
||||
x =>
|
||||
{
|
||||
if (!hasRunStackClearingCommand)
|
||||
{
|
||||
/*
|
||||
* The first stack-clearing operator, which must be one of hstem, hstemhm, vstem, vstemhm, cntrmask, hintmask, hmoveto, vmoveto,
|
||||
* rmoveto, or endchar, takes an additional argument — the width (as described earlier), which may be expressed as zero or one numeric argument.
|
||||
*/
|
||||
hasRunStackClearingCommand = true;
|
||||
switch (x.Name)
|
||||
{
|
||||
case "hstem":
|
||||
case "hstemhm":
|
||||
case "vstemhm":
|
||||
case "vstem":
|
||||
{
|
||||
var oddArgCount = context.Stack.Length % 2 != 0;
|
||||
if (oddArgCount)
|
||||
{
|
||||
context.Width = context.Stack.PopBottom();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "hmoveto":
|
||||
case "vmoveto":
|
||||
SetWidthFromArgumentsIfPresent(context, 1);
|
||||
break;
|
||||
case "rmoveto":
|
||||
SetWidthFromArgumentsIfPresent(context, 2);
|
||||
break;
|
||||
case "cntrmask":
|
||||
case "hintmask":
|
||||
case "endchar:":
|
||||
SetWidthFromArgumentsIfPresent(context, 0);
|
||||
break;
|
||||
default:
|
||||
hasRunStackClearingCommand = false;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
x.Run(context);
|
||||
});
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
return context.Path;
|
||||
}
|
||||
|
||||
private static void SetWidthFromArgumentsIfPresent(Type2BuildCharContext context, int expectedArgumentLength)
|
||||
{
|
||||
if (context.Stack.Length > expectedArgumentLength)
|
||||
{
|
||||
context.Width = context.Stack.PopBottom();
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandSequence
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Charsets;
|
||||
using CharStrings;
|
||||
@@ -147,6 +148,15 @@
|
||||
throw new ArgumentOutOfRangeException($"Unexpected CharString type in CFF font: {topDictionary.CharStringType}.");
|
||||
}
|
||||
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
foreach (var pair in charStrings.CharStrings)
|
||||
{
|
||||
var path = Type2CharStrings.Run(pair.Value);
|
||||
var svg = path.ToFullSvg();
|
||||
}
|
||||
}
|
||||
|
||||
return new CompactFontFormatFont(topDictionary, privateDictionary, charset, Union<Type1CharStrings, Type2CharStrings>.Two(charStrings));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user