Dump glyph coordinates

This commit is contained in:
Eugen Wissner 2024-01-29 20:13:43 +01:00
parent 1cce3c893d
commit 22d37b0972
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0

View File

@ -662,15 +662,41 @@ dumpGlyf (GlyfTable glyfDescriptions) = dumpCaption "'glyf' Table - Glyf data"
<> foldMap dumpEndPoint (Vector.indexed endPtsOfContours) <> newlineBuilder
<> " Length of Instructions: "
<> Text.Builder.decimal (Vector.length instructions) <> newlineBuilder
<> " Flags" <> newlineBuilder
<> newlineBuilder <> " Flags" <> newlineBuilder
<> " -----" <> newlineBuilder
<> foldMap dumpFlag (Vector.indexed coordinates) <> newlineBuilder <> newlineBuilder
dumpGlyphDefinition _ = ""
dumpFlag (coordinateIndex, GlyphCoordinate{..})
<> foldMap dumpFlag (Vector.indexed coordinates) <> newlineBuilder
<> " Coordinates" <> newlineBuilder
<> " -----------" <> newlineBuilder
<> dumpCoordinates coordinates
dumpGlyphDefinition _ = "" -- TODO
dumpFlag (coordinateIndex, GlyphCoordinate{..}) -- TODO
= " " <> justifyNumber 2 coordinateIndex <> ": "
<> Text.Builder.decimal coordinateX <> " " <> Text.Builder.decimal coordinateY <> " "
<> (if onCurve then "On" else "Off")
<> newlineBuilder
dumpCoordinates coordinates =
let initial = ("", GlyphCoordinate 0 0 True)
in fst $ Vector.ifoldl' foldCoordinate initial coordinates
foldCoordinate
:: (Text.Builder.Builder, GlyphCoordinate)
-> Int
-> GlyphCoordinate
-> (Text.Builder.Builder, GlyphCoordinate)
foldCoordinate (accumulator, absCoordinate) coordinateIndex relCoordinate =
let nextAbs = GlyphCoordinate
{ coordinateX = sumCoordinate (getField @"coordinateX") relCoordinate absCoordinate
, coordinateY = sumCoordinate (getField @"coordinateY") relCoordinate absCoordinate
, onCurve = getField @"onCurve" relCoordinate -- Not used.
}
newLine = " " <> justifyNumber 2 coordinateIndex
<> " Rel " <> dumpCoordinate relCoordinate
<> " -> Abs " <> dumpCoordinate nextAbs
<> newlineBuilder
in (accumulator <> newLine, nextAbs)
sumCoordinate getAxis relCoordinate absCoordinate =
getAxis relCoordinate + getAxis absCoordinate
dumpCoordinate GlyphCoordinate{..}
= "(" <> justifyNumber 7 coordinateX <> ", "
<> justifyNumber 7 coordinateY <> ")"
dumpTables
:: Megaparsec.State ByteString Void