Skip to content

Commit

Permalink
Remap accents to directional single-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Jul 3, 2017
1 parent e792226 commit ca44f60
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 5 deletions.
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions lib/postproc/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion preview-canvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="initial-scale=1, minimum-scale=1" />
<link rel="stylesheet" type="text/css" href="node_modules/urw-core35-fonts/index.css" />
<title>Canvas Preview</title>

<style>
Expand All @@ -15,6 +16,7 @@
position: fixed;
top: 0;
left: 0;
width: 100vw;
}
</style>
</head>
Expand All @@ -27,7 +29,7 @@
<script>
"use strict";

const source = require("fs").readFileSync("./tmp/perlre.out", "utf8");
const source = require("fs").readFileSync("./test/fixtures/pdf-fonts.out", "utf8");

const CanvasRenderer = require("./lib/postproc/canvas.js");
const renderer = new CanvasRenderer();
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!quote-mystery.pdf
pdf-fonts.out
85 changes: 85 additions & 0 deletions test/fixtures/pdf-fonts.roff
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'\" ==========================================
'\" Print a small sample of each core PDF font
'\" ------------------------------------------
.ds LQ `
.ds RQ '
.ds QQ ABC \\*(LQ123\\*(RQ XYZ
.
.ad r
.ta (2.5i)
.ps 32p
.vs 2m
.
.de test
. ft \\$1
. if '\\nV'1' .tm Setting Font: \\$1
\\$1\t\\*(QQ
. br
..
.
.test AB
.test ABI
.test AI
.test AR
.test BMB
.test BMBI
.test BMI
.test BMR
.test CB
.test CBI
.test CI
.test CR
.test HB
.test HBI
.test HI
.test HNB
.test HNBI
.test HNI
.test HNR
.test HR
.test NB
.test NBI
.test NI
.test NR
.test PB
.test PBI
.test PI
.test PR
.test TB
.test TBI
.test TI
.test TR
.test U-AB
.test U-ABI
.test U-AI
.test U-AR
.test U-BMB
.test U-BMBI
.test U-BMI
.test U-BMR
.test U-CB
.test U-CBI
.test U-CI
.test U-CR
.test U-HB
.test U-HBI
.test U-HI
.test U-HNB
.test U-HNBI
.test U-HNI
.test U-HNR
.test U-HR
.test U-NB
.test U-NBI
.test U-NI
.test U-NR
.test U-PB
.test U-PBI
.test U-PI
.test U-PR
.test U-TB
.test U-TBI
.test U-TI
.test U-TR
.test U-ZCMI
.test ZCMI
Binary file added test/fixtures/quote-mystery.pdf
Binary file not shown.

0 comments on commit ca44f60

Please sign in to comment.