From ca44f6047279243669ca3fb0ed71f8f2ddfd6842 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 3 Jul 2017 21:33:17 +1000 Subject: [PATCH] Remap accents to directional single-quotes See: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html#postscript --- Makefile | 24 +++++++-- lib/postproc/canvas.js | 9 ++++ preview-canvas.html | 4 +- test/fixtures/.gitignore | 2 + test/fixtures/pdf-fonts.roff | 85 ++++++++++++++++++++++++++++++++ test/fixtures/quote-mystery.pdf | Bin 0 -> 4766 bytes 6 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/.gitignore create mode 100644 test/fixtures/pdf-fonts.roff create mode 100644 test/fixtures/quote-mystery.pdf diff --git a/Makefile b/Makefile index 74b3d06..d09b788 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,27 @@ -pdfs := $(wildcard tmp/*.pdf) +all: pdfs font-list -all: $(pdfs) +pdfs: $(wildcard tmp/*.pdf) %.pdf: %.out @gropdf -d < $^ > $@ -watch:; @watchman -- trigger . _ 'tmp/*.out' -- make all -unwatch:; @watchman -- watch-del . + +font-list := test/fixtures/pdf-fonts +font-list: $(font-list).pdf + +$(font-list).pdf: $(font-list).roff + @ groff -Tpdf -Z $(if $(VERBOSE),-rV1) $< \ + | tee $(font-list).out \ + | gropdf -d > $@ + + +watch = watchman -- trigger . $(1) '$(2)' -- make $(1) + +watch: + @$(call watch,pdfs,tmp/*.out) + @$(call watch,font-list,$(font-list).roff) + +unwatch: + @watchman -- watch-del . .PHONY: watch unwatch diff --git a/lib/postproc/canvas.js b/lib/postproc/canvas.js index 6d3981b..64ad0d6 100644 --- a/lib/postproc/canvas.js +++ b/lib/postproc/canvas.js @@ -45,6 +45,7 @@ class CanvasRenderer extends Postprocessor{ resetFontStyles(){ this.fixKerning = true; + this.fixQuotes = true; this.fontStyles = Object.assign({}, fontStyles); this.fonts = [0, 0, 0, 0, 0, 0, "S", "ZD"]; this.fonts.forEach((font, index) => { @@ -586,6 +587,7 @@ class CanvasRenderer extends Postprocessor{ print(text){ + text = this.remapChars(text); this.context.save(); if(null !== this.tm){ this.context.translate(this.x, this.y); @@ -623,6 +625,13 @@ class CanvasRenderer extends Postprocessor{ } + remapChars(data){ + return this.fixQuotes + ? data.replace(/`/g, "\u{2018}").replace(/'/g, "\u{2019}") + : data; + } + + setColour(data){ this.colour = this.parseColour(data); this.context.fillStyle = this.colour; diff --git a/preview-canvas.html b/preview-canvas.html index bf13e28..916038e 100644 --- a/preview-canvas.html +++ b/preview-canvas.html @@ -4,6 +4,7 @@ + Canvas Preview @@ -27,7 +29,7 @@