Showing
3 changed files
with
20 additions
and
2 deletions
| @@ -17,11 +17,14 @@ | @@ -17,11 +17,14 @@ | ||
| 17 | DART_SRC=$(shell find . -name '*.dart') | 17 | DART_SRC=$(shell find . -name '*.dart') |
| 18 | CLNG_SRC=$(shell find . -name '*.java' -o -name '*.m' -o -name '*.h') | 18 | CLNG_SRC=$(shell find . -name '*.java' -o -name '*.m' -o -name '*.h') |
| 19 | 19 | ||
| 20 | -all: pdf/open-sans.ttf format | 20 | +all: pdf/open-sans.ttf pdf/roboto.ttf format |
| 21 | 21 | ||
| 22 | pdf/open-sans.ttf: | 22 | pdf/open-sans.ttf: |
| 23 | curl -L "https://github.com/google/fonts/raw/master/apache/opensans/OpenSans-Regular.ttf" > $@ | 23 | curl -L "https://github.com/google/fonts/raw/master/apache/opensans/OpenSans-Regular.ttf" > $@ |
| 24 | 24 | ||
| 25 | +pdf/roboto.ttf: | ||
| 26 | + curl -L "https://github.com/google/fonts/raw/master/apache/robotomono/RobotoMono-Regular.ttf" > $@ | ||
| 27 | + | ||
| 25 | format: format-dart format-clang | 28 | format: format-dart format-clang |
| 26 | 29 | ||
| 27 | format-dart: $(DART_SRC) | 30 | format-dart: $(DART_SRC) |
| @@ -58,7 +58,8 @@ class PDFTTFFont extends PDFFont { | @@ -58,7 +58,8 @@ class PDFTTFFont extends PDFFont { | ||
| 58 | return super.glyphAdvance(charCode); | 58 | return super.glyphAdvance(charCode); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | - return (font.advanceWidth[g]) ?? super.glyphAdvance(charCode); | 61 | + return (g < font.advanceWidth.length ? font.advanceWidth[g] : null) ?? |
| 62 | + super.glyphAdvance(charCode); | ||
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | @override | 65 | @override |
| @@ -30,6 +30,20 @@ void main() { | @@ -30,6 +30,20 @@ void main() { | ||
| 30 | g.setColor(new PDFColor(0.3, 0.3, 0.3)); | 30 | g.setColor(new PDFColor(0.3, 0.3, 0.3)); |
| 31 | g.drawString(ttf, FS, s, 50.0, 30.0); | 31 | g.drawString(ttf, FS, s, 50.0, 30.0); |
| 32 | 32 | ||
| 33 | + var roboto = new PDFTTFFont( | ||
| 34 | + pdf, | ||
| 35 | + (new File("roboto.ttf").readAsBytesSync() as Uint8List) | ||
| 36 | + .buffer | ||
| 37 | + .asByteData()); | ||
| 38 | + | ||
| 39 | + r = roboto.stringBounds(s); | ||
| 40 | + print(r); | ||
| 41 | + g.setColor(new PDFColor(0.0, 1.0, 1.0)); | ||
| 42 | + g.drawRect(50.0 + r.x * FS, 130.0 + r.y * FS, r.w * FS, r.h * FS); | ||
| 43 | + g.fillPath(); | ||
| 44 | + g.setColor(new PDFColor(0.3, 0.3, 0.3)); | ||
| 45 | + g.drawString(roboto, FS, s, 50.0, 130.0); | ||
| 46 | + | ||
| 33 | var file = new File('file2.pdf'); | 47 | var file = new File('file2.pdf'); |
| 34 | file.writeAsBytesSync(pdf.save()); | 48 | file.writeAsBytesSync(pdf.save()); |
| 35 | }); | 49 | }); |
-
Please register or login to post a comment