diff --git a/pitfall/pdfkit/lib/mixins/annotations.js b/pitfall/pdfkit/lib/mixins/annotations.js deleted file mode 100644 index 4eb88b31..00000000 --- a/pitfall/pdfkit/lib/mixins/annotations.js +++ /dev/null @@ -1,133 +0,0 @@ -// Generated by CoffeeScript 1.12.5 -(function() { - module.exports = { - annotate: function(x, y, w, h, options) { - var key, ref, val; - options.Type = 'Annot'; - options.Rect = this._convertRect(x, y, w, h); - options.Border = [0, 0, 0]; - if (options.Subtype !== 'Link') { - if (options.C == null) { - options.C = this._normalizeColor(options.color || [0, 0, 0]); - } - } - delete options.color; - if (typeof options.Dest === 'string') { - options.Dest = new String(options.Dest); - } - for (key in options) { - val = options[key]; - options[key[0].toUpperCase() + key.slice(1)] = val; - } - ref = this.ref(options); - this.page.annotations.push(ref); - ref.end(); - return this; - }, - note: function(x, y, w, h, contents, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'Text'; - options.Contents = new String(contents); - options.Name = 'Comment'; - if (options.color == null) { - options.color = [243, 223, 92]; - } - return this.annotate(x, y, w, h, options); - }, - link: function(x, y, w, h, url, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'Link'; - options.A = this.ref({ - S: 'URI', - URI: new String(url) - }); - options.A.end(); - return this.annotate(x, y, w, h, options); - }, - _markup: function(x, y, w, h, options) { - var ref1, x1, x2, y1, y2; - if (options == null) { - options = {}; - } - ref1 = this._convertRect(x, y, w, h), x1 = ref1[0], y1 = ref1[1], x2 = ref1[2], y2 = ref1[3]; - options.QuadPoints = [x1, y2, x2, y2, x1, y1, x2, y1]; - options.Contents = new String; - return this.annotate(x, y, w, h, options); - }, - highlight: function(x, y, w, h, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'Highlight'; - if (options.color == null) { - options.color = [241, 238, 148]; - } - return this._markup(x, y, w, h, options); - }, - underline: function(x, y, w, h, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'Underline'; - return this._markup(x, y, w, h, options); - }, - strike: function(x, y, w, h, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'StrikeOut'; - return this._markup(x, y, w, h, options); - }, - lineAnnotation: function(x1, y1, x2, y2, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'Line'; - options.Contents = new String; - options.L = [x1, this.page.height - y1, x2, this.page.height - y2]; - return this.annotate(x1, y1, x2, y2, options); - }, - rectAnnotation: function(x, y, w, h, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'Square'; - options.Contents = new String; - return this.annotate(x, y, w, h, options); - }, - ellipseAnnotation: function(x, y, w, h, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'Circle'; - options.Contents = new String; - return this.annotate(x, y, w, h, options); - }, - textAnnotation: function(x, y, w, h, text, options) { - if (options == null) { - options = {}; - } - options.Subtype = 'FreeText'; - options.Contents = new String(text); - options.DA = new String; - return this.annotate(x, y, w, h, options); - }, - _convertRect: function(x1, y1, w, h) { - var m0, m1, m2, m3, m4, m5, ref1, x2, y2; - y2 = y1; - y1 += h; - x2 = x1 + w; - ref1 = this._ctm, m0 = ref1[0], m1 = ref1[1], m2 = ref1[2], m3 = ref1[3], m4 = ref1[4], m5 = ref1[5]; - x1 = m0 * x1 + m2 * y1 + m4; - y1 = m1 * x1 + m3 * y1 + m5; - x2 = m0 * x2 + m2 * y2 + m4; - y2 = m1 * x2 + m3 * y2 + m5; - return [x1, y1, x2, y2]; - } - }; - -}).call(this); diff --git a/pitfall/pdfkit/lib/mixins/text.coffee b/pitfall/pdfkit/lib/mixins/text.coffee index a371ac6f..9a59c7a2 100644 --- a/pitfall/pdfkit/lib/mixins/text.coffee +++ b/pitfall/pdfkit/lib/mixins/text.coffee @@ -30,6 +30,7 @@ module.exports = text = text.replace(/\s{2,}/g, ' ') # word wrapping + #console.log("options.width=" + options.width) if options.width wrapper = @_wrapper unless wrapper @@ -42,6 +43,7 @@ module.exports = # render paragraphs as single lines else + #console.log("line callback!") lineCallback line, options for line in text.split '\n' return this @@ -154,6 +156,7 @@ module.exports = return options _line: (text, options = {}, wrapper) -> + #console.log("in _line!") @_fragment text, @x, @y, options lineGap = options.lineGap or @_lineGap or 0 @@ -188,21 +191,29 @@ module.exports = spaceWidth = @widthOfString(' ') + characterSpacing wordSpacing = Math.max 0, (options.lineWidth - textWidth) / Math.max(1, words.length - 1) - spaceWidth + #console.log("momo me" + options.textWidth) + # calculate the actual rendered width of the string after word and character spacing - renderedWidth = options.textWidth + (wordSpacing * (options.wordCount - 1)) + (characterSpacing * (text.length - 1)) + + renderedWidth = (options.textWidth || @widthOfString(text, options)) + (wordSpacing * ((options.wordCount || 0) - 1)) + (characterSpacing * (text.length - 1)) # create link annotations if the link option is given if options.link @link x, y, renderedWidth, @currentLineHeight(), options.link + #console.log("mama me") + # create underline or strikethrough line if options.underline or options.strike + console.log("enter underline") @save() @strokeColor @_fillColor... unless options.stroke lineWidth = if @_fontSize < 10 then 0.5 else Math.floor(@_fontSize / 10) @lineWidth lineWidth + #console.log("lineWidth" + lineWidth) + d = if options.underline then 1 else 2 lineY = y + @currentLineHeight() / d lineY -= lineWidth if options.underline @@ -220,6 +231,8 @@ module.exports = # add current font to page if necessary @page.fonts[@_font.id] ?= @_font.ref() + #console.log("mercy me") + # begin the text object @addContent "BT" diff --git a/pitfall/pdfkit/lib/mixins/text.js b/pitfall/pdfkit/lib/mixins/text.js deleted file mode 100644 index bf0e0f11..00000000 --- a/pitfall/pdfkit/lib/mixins/text.js +++ /dev/null @@ -1,338 +0,0 @@ -// Generated by CoffeeScript 1.12.5 -(function() { - var LineWrapper, number; - - LineWrapper = require('../line_wrapper'); - - number = require('../object').number; - - module.exports = { - initText: function() { - this.x = 0; - this.y = 0; - return this._lineGap = 0; - }, - lineGap: function(_lineGap) { - this._lineGap = _lineGap; - return this; - }, - moveDown: function(lines) { - if (lines == null) { - lines = 1; - } - this.y += this.currentLineHeight(true) * lines + this._lineGap; - return this; - }, - moveUp: function(lines) { - if (lines == null) { - lines = 1; - } - this.y -= this.currentLineHeight(true) * lines + this._lineGap; - return this; - }, - _text: function(text, x, y, options, lineCallback) { - var j, len, line, ref, wrapper; - options = this._initOptions(x, y, options); - text = '' + text; - if (options.wordSpacing) { - text = text.replace(/\s{2,}/g, ' '); - } - if (options.width) { - wrapper = this._wrapper; - if (!wrapper) { - wrapper = new LineWrapper(this, options); - wrapper.on('line', lineCallback); - } - this._wrapper = options.continued ? wrapper : null; - this._textOptions = options.continued ? options : null; - wrapper.wrap(text, options); - } else { - ref = text.split('\n'); - for (j = 0, len = ref.length; j < len; j++) { - line = ref[j]; - lineCallback(line, options); - } - } - return this; - }, - text: function(text, x, y, options) { - return this._text(text, x, y, options, this._line.bind(this)); - }, - widthOfString: function(string, options) { - if (options == null) { - options = {}; - } - return this._font.widthOfString(string, this._fontSize, options.features) + (options.characterSpacing || 0) * (string.length - 1); - }, - heightOfString: function(text, options) { - var height, lineGap, ref, x, y; - if (options == null) { - options = {}; - } - ref = this, x = ref.x, y = ref.y; - options = this._initOptions(options); - options.height = 2e308; - lineGap = options.lineGap || this._lineGap || 0; - this._text(text, this.x, this.y, options, (function(_this) { - return function(line, options) { - return _this.y += _this.currentLineHeight(true) + lineGap; - }; - })(this)); - height = this.y - y; - this.x = x; - this.y = y; - return height; - }, - list: function(list, x, y, options, wrapper) { - var flatten, i, indent, itemIndent, items, level, levels, midLine, r; - options = this._initOptions(x, y, options); - midLine = Math.round((this._font.ascender / 1000 * this._fontSize) / 2); - r = options.bulletRadius || Math.round((this._font.ascender / 1000 * this._fontSize) / 3); - indent = options.textIndent || r * 5; - itemIndent = options.bulletIndent || r * 8; - level = 1; - items = []; - levels = []; - flatten = function(list) { - var i, item, j, len, results; - results = []; - for (i = j = 0, len = list.length; j < len; i = ++j) { - item = list[i]; - if (Array.isArray(item)) { - level++; - flatten(item); - results.push(level--); - } else { - items.push(item); - results.push(levels.push(level)); - } - } - return results; - }; - flatten(list); - wrapper = new LineWrapper(this, options); - wrapper.on('line', this._line.bind(this)); - level = 1; - i = 0; - wrapper.on('firstLine', (function(_this) { - return function() { - var diff, l; - if ((l = levels[i++]) !== level) { - diff = itemIndent * (l - level); - _this.x += diff; - wrapper.lineWidth -= diff; - level = l; - } - _this.circle(_this.x - indent + r, _this.y + midLine, r); - return _this.fill(); - }; - })(this)); - wrapper.on('sectionStart', (function(_this) { - return function() { - var pos; - pos = indent + itemIndent * (level - 1); - _this.x += pos; - return wrapper.lineWidth -= pos; - }; - })(this)); - wrapper.on('sectionEnd', (function(_this) { - return function() { - var pos; - pos = indent + itemIndent * (level - 1); - _this.x -= pos; - return wrapper.lineWidth += pos; - }; - })(this)); - wrapper.wrap(items.join('\n'), options); - return this; - }, - _initOptions: function(x, y, options) { - var key, margins, ref, val; - if (x == null) { - x = {}; - } - if (options == null) { - options = {}; - } - if (typeof x === 'object') { - options = x; - x = null; - } - options = (function() { - var k, opts, v; - opts = {}; - for (k in options) { - v = options[k]; - opts[k] = v; - } - return opts; - })(); - if (this._textOptions) { - ref = this._textOptions; - for (key in ref) { - val = ref[key]; - if (key !== 'continued') { - if (options[key] == null) { - options[key] = val; - } - } - } - } - if (x != null) { - this.x = x; - } - if (y != null) { - this.y = y; - } - if (options.lineBreak !== false) { - margins = this.page.margins; - if (options.width == null) { - options.width = this.page.width - this.x - margins.right; - } - } - options.columns || (options.columns = 0); - if (options.columnGap == null) { - options.columnGap = 18; - } - return options; - }, - _line: function(text, options, wrapper) { - var lineGap; - if (options == null) { - options = {}; - } - this._fragment(text, this.x, this.y, options); - lineGap = options.lineGap || this._lineGap || 0; - if (!wrapper) { - return this.x += this.widthOfString(text); - } else { - return this.y += this.currentLineHeight(true) + lineGap; - } - }, - _fragment: function(text, x, y, options) { - var addSegment, align, base, characterSpacing, commands, d, encoded, encodedWord, flush, hadOffset, i, j, last, len, len1, lineWidth, lineY, m, mode, name, pos, positions, positionsWord, ref, ref1, renderedWidth, scale, spaceWidth, textWidth, word, wordSpacing, words; - text = ('' + text).replace(/\n/g, ''); - if (text.length === 0) { - return; - } - align = options.align || 'left'; - wordSpacing = options.wordSpacing || 0; - characterSpacing = options.characterSpacing || 0; - if (options.width) { - switch (align) { - case 'right': - textWidth = this.widthOfString(text.replace(/\s+$/, ''), options); - x += options.lineWidth - textWidth; - break; - case 'center': - x += options.lineWidth / 2 - options.textWidth / 2; - break; - case 'justify': - words = text.trim().split(/\s+/); - textWidth = this.widthOfString(text.replace(/\s+/g, ''), options); - spaceWidth = this.widthOfString(' ') + characterSpacing; - wordSpacing = Math.max(0, (options.lineWidth - textWidth) / Math.max(1, words.length - 1) - spaceWidth); - } - } - renderedWidth = options.textWidth + (wordSpacing * (options.wordCount - 1)) + (characterSpacing * (text.length - 1)); - if (options.link) { - this.link(x, y, renderedWidth, this.currentLineHeight(), options.link); - } - if (options.underline || options.strike) { - this.save(); - if (!options.stroke) { - this.strokeColor.apply(this, this._fillColor); - } - lineWidth = this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10); - this.lineWidth(lineWidth); - d = options.underline ? 1 : 2; - lineY = y + this.currentLineHeight() / d; - if (options.underline) { - lineY -= lineWidth; - } - this.moveTo(x, lineY); - this.lineTo(x + renderedWidth, lineY); - this.stroke(); - this.restore(); - } - this.save(); - this.transform(1, 0, 0, -1, 0, this.page.height); - y = this.page.height - y - (this._font.ascender / 1000 * this._fontSize); - if ((base = this.page.fonts)[name = this._font.id] == null) { - base[name] = this._font.ref(); - } - this.addContent("BT"); - this.addContent("1 0 0 1 " + (number(x)) + " " + (number(y)) + " Tm"); - this.addContent("/" + this._font.id + " " + (number(this._fontSize)) + " Tf"); - mode = options.fill && options.stroke ? 2 : options.stroke ? 1 : 0; - if (mode) { - this.addContent(mode + " Tr"); - } - if (characterSpacing) { - this.addContent((number(characterSpacing)) + " Tc"); - } - if (wordSpacing) { - words = text.trim().split(/\s+/); - wordSpacing += this.widthOfString(' ') + characterSpacing; - wordSpacing *= 1000 / this._fontSize; - encoded = []; - positions = []; - for (j = 0, len = words.length; j < len; j++) { - word = words[j]; - ref = this._font.encode(word, options.features), encodedWord = ref[0], positionsWord = ref[1]; - encoded.push.apply(encoded, encodedWord); - positions.push.apply(positions, positionsWord); - positions[positions.length - 1].xAdvance += wordSpacing; - } - } else { - ref1 = this._font.encode(text, options.features), encoded = ref1[0], positions = ref1[1]; - } - scale = this._fontSize / 1000; - commands = []; - last = 0; - hadOffset = false; - addSegment = (function(_this) { - return function(cur) { - var advance, hex; - if (last < cur) { - hex = encoded.slice(last, cur).join(''); - advance = positions[cur - 1].xAdvance - positions[cur - 1].advanceWidth; - commands.push("<" + hex + "> " + (number(-advance))); - } - return last = cur; - }; - })(this); - flush = (function(_this) { - return function(i) { - addSegment(i); - if (commands.length > 0) { - _this.addContent("[" + (commands.join(' ')) + "] TJ"); - return commands.length = 0; - } - }; - })(this); - for (i = m = 0, len1 = positions.length; m < len1; i = ++m) { - pos = positions[i]; - if (pos.xOffset || pos.yOffset) { - flush(i); - this.addContent("1 0 0 1 " + (number(x + pos.xOffset * scale)) + " " + (number(y + pos.yOffset * scale)) + " Tm"); - flush(i + 1); - hadOffset = true; - } else { - if (hadOffset) { - this.addContent("1 0 0 1 " + (number(x)) + " " + (number(y)) + " Tm"); - hadOffset = false; - } - if (pos.xAdvance - pos.advanceWidth !== 0) { - addSegment(i + 1); - } - } - x += pos.xAdvance * scale; - } - flush(i); - this.addContent("ET"); - return this.restore(); - } - }; - -}).call(this); diff --git a/pitfall/pitfall/alltest.rkt b/pitfall/pitfall/alltest.rkt index 9eaa2ece..084b754a 100644 --- a/pitfall/pitfall/alltest.rkt +++ b/pitfall/pitfall/alltest.rkt @@ -11,5 +11,6 @@ pitfall/test/test8 pitfall/test/test09 pitfall/test/test10 + pitfall/test/test11 pitfall/page-test (submod pitfall/zlib test))) \ No newline at end of file diff --git a/pitfall/pitfall/annotations.rkt b/pitfall/pitfall/annotations.rkt index adf39102..3e2d5049 100644 --- a/pitfall/pitfall/annotations.rkt +++ b/pitfall/pitfall/annotations.rkt @@ -52,8 +52,8 @@ [y1 (+ y1 h)] [x2 (+ x1 w)]) (match-define (list m0 m1 m2 m3 m4 m5) (· this _ctm)) - (list - (+ (* x1 m0) (* y1 m2) m4) - (+ (* x1 m1) (* y1 m3) m5) - (+ (* x2 m0) (* y2 m2) m4) - (+ (* x2 m1) (* y2 m3) m5)))) \ No newline at end of file + (let* ([x1 (+ (* x1 m0) (* y1 m2) m4)] + [y1 (+ (* x1 m1) (* y1 m3) m5)] + [x2 (+ (* x2 m0) (* y2 m2) m4)] + [y2 (+ (* x2 m1) (* y2 m3) m5)]) + (list x1 y1 x2 y2)))) \ No newline at end of file diff --git a/pitfall/pitfall/page.rkt b/pitfall/pitfall/page.rkt index 4df81a2b..0a5239d4 100644 --- a/pitfall/pitfall/page.rkt +++ b/pitfall/pitfall/page.rkt @@ -64,8 +64,8 @@ (define/contract (annotations this [annot #f]) (() (any/c) . ->*m . void?) (if (not annot) - (hash-ref! (· this resources payload) 'Annots null) - (hash-update! (· this resources payload) 'Annots (λ (val) (cons annot val)) null))) + (hash-ref! (· this dictionary payload) 'Annots null) + (hash-update! (· this dictionary payload) 'Annots (λ (val) (cons annot val)) null))) (define/contract (maxY this) diff --git a/pitfall/pitfall/test/test11.coffee b/pitfall/pitfall/test/test11.coffee index b0d5216a..8116f820 100644 --- a/pitfall/pitfall/test/test11.coffee +++ b/pitfall/pitfall/test/test11.coffee @@ -5,7 +5,7 @@ make = (doc) -> # Add some text with annotations doc.fillColor("blue") .font('Helvetica', 30) - .text('Here is a link!', 100, 100, { link: 'http://google.com/', underline: true }) + .text('Here is a link!', 100, 100, { link: 'http://google.com/', underline: true, width: false}) doc.end() diff --git a/pitfall/pitfall/test/test11.rkt b/pitfall/pitfall/test/test11.rkt index 3cdc1844..c4e65852 100644 --- a/pitfall/pitfall/test/test11.rkt +++ b/pitfall/pitfall/test/test11.rkt @@ -8,5 +8,8 @@ 'link "http://google.com/" 'underline #t)])) +(define-runtime-path this "test11rkt.pdf") +(make-doc this #f proc #:pdfkit #f) + (define-runtime-path that "test11crkt.pdf") -(make-doc that #t proc #:test #f) +(make-doc that #t proc) diff --git a/pitfall/pitfall/test/test11c.pdf b/pitfall/pitfall/test/test11c.pdf index d35e7f15..daa5089c 100644 --- a/pitfall/pitfall/test/test11c.pdf +++ b/pitfall/pitfall/test/test11c.pdf @@ -53,7 +53,7 @@ endobj << /Producer (PDFKit) /Creator (PDFKit) -/CreationDate (D:20170527044501Z) +/CreationDate (D:20170529030148Z) >> endobj 10 0 obj diff --git a/pitfall/pitfall/test/test11crkt copy.pdf b/pitfall/pitfall/test/test11crkt copy.pdf new file mode 100644 index 00000000..a26229c2 --- /dev/null +++ b/pitfall/pitfall/test/test11crkt copy.pdf @@ -0,0 +1,112 @@ +%PDF-1.3 +% +6 0 obj +<< +/ca 1 +/Type /ExtGState +>> +endobj +7 0 obj +<< +/URI (http://google.com/) +/S /URI +>> +endobj +8 0 obj +<< +/A 7 0 R +/Border [0 0 0] +/Subtype /Link +/Rect [100 664.25 281.71 692] +/Type /Annot +>> +endobj +9 0 obj +<< +/CA 1 +/Type /ExtGState +>> +endobj +5 0 obj +<< +/Parent 1 0 R +/Resources 4 0 R +/Contents 3 0 R +/MediaBox [0 0 612 792] +/Annots [8 0 R] +/Type /Page +>> +endobj +4 0 obj +<< +/Font << +/F1 10 0 R +>> +/ExtGState << +/Gs2 9 0 R +/Gs1 6 0 R +>> +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +>> +endobj +3 0 obj +<< +/Length 161 +/Filter /FlateDecode +>> +stream +xe +0 y[aS]oee)AB~H%ƂT|Gc[cL0M S|@&k/t35( d6G2O Yan*Mf%, Y|JQ*gZ9c&'0P +endstream +endobj +11 0 obj +<< +/CreationDate (D:19700101000000Z) +/Creator (PITKIT) +/Producer (PITKIT) +>> +endobj +10 0 obj +<< +/BaseFont /Helvetica +/Encoding /WinAnsiEncoding +/Subtype /Type1 +/Type /Font +>> +endobj +2 0 obj +<< +/Pages 1 0 R +/Type /Catalog +>> +endobj +1 0 obj +<< +/Kids [5 0 R] +/Count 1 +/Type /Pages +>> +endobj +xref +0 12 +0000000000 65535 f +0000000984 00000 n +0000000935 00000 n +0000000511 00000 n +0000000382 00000 n +0000000262 00000 n +0000000015 00000 n +0000000059 00000 n +0000000114 00000 n +0000000218 00000 n +0000000837 00000 n +0000000744 00000 n +trailer +<< +/Info 11 0 R +/Root 2 0 R +/Size 12 +>> +startxref +1041 +%%EOF diff --git a/pitfall/pitfall/test/test11crkt.pdf b/pitfall/pitfall/test/test11crkt.pdf index 52d68e8b..a26229c2 100644 --- a/pitfall/pitfall/test/test11crkt.pdf +++ b/pitfall/pitfall/test/test11crkt.pdf @@ -17,7 +17,7 @@ endobj /A 7 0 R /Border [0 0 0] /Subtype /Link -/Rect [100 664.25 100 692] +/Rect [100 664.25 281.71 692] /Type /Annot >> endobj @@ -33,12 +33,12 @@ endobj /Resources 4 0 R /Contents 3 0 R /MediaBox [0 0 612 792] +/Annots [8 0 R] /Type /Page >> endobj 4 0 obj << -/Annots [8 0 R] /Font << /F1 10 0 R >> @@ -51,13 +51,12 @@ endobj endobj 3 0 obj << -/Length 153 +/Length 161 /Filter /FlateDecode >> stream xe -0 y[ӵ7REp|~Sa !?*Vcޥ3aP92#gI~&|*.)qi9Y/ IXxv2A96 -f4[u(IGn9i ?J. +0 y[aS]oee)AB~H%ƂT|Gc[cL0M S|@&k/t35( d6G2O Yan*Mf%, Y|JQ*gZ9c&'0P endstream endobj 11 0 obj @@ -91,17 +90,17 @@ endobj xref 0 12 0000000000 65535 f -0000000973 00000 n -0000000924 00000 n -0000000508 00000 n -0000000363 00000 n -0000000259 00000 n +0000000984 00000 n +0000000935 00000 n +0000000511 00000 n +0000000382 00000 n +0000000262 00000 n 0000000015 00000 n 0000000059 00000 n 0000000114 00000 n -0000000215 00000 n -0000000826 00000 n -0000000733 00000 n +0000000218 00000 n +0000000837 00000 n +0000000744 00000 n trailer << /Info 11 0 R @@ -109,5 +108,5 @@ trailer /Size 12 >> startxref -1030 +1041 %%EOF diff --git a/pitfall/pitfall/test/test11rkt copy.pdf b/pitfall/pitfall/test/test11rkt copy.pdf new file mode 100644 index 00000000..a34b1f05 --- /dev/null +++ b/pitfall/pitfall/test/test11rkt copy.pdf @@ -0,0 +1,131 @@ +%PDF-1.3 +% +6 0 obj +<< +/ca 1 +/Type /ExtGState +>> +endobj +7 0 obj +<< +/URI (http://google.com/) +/S /URI +>> +endobj +8 0 obj +<< +/A 7 0 R +/Border [0 0 0] +/Subtype /Link +/Rect [100 664.25 281.71 692] +/Type /Annot +>> +endobj +9 0 obj +<< +/CA 1 +/Type /ExtGState +>> +endobj +5 0 obj +<< +/Parent 1 0 R +/Resources 4 0 R +/Contents 3 0 R +/MediaBox [0 0 612 792] +/Annots [8 0 R] +/Type /Page +>> +endobj +4 0 obj +<< +/Font << +/F1 10 0 R +>> +/ExtGState << +/Gs2 9 0 R +/Gs1 6 0 R +>> +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +>> +endobj +3 0 obj +<< +/Length 221 +>> +stream +1 0 0 -1 0 792 cm +/DeviceRGB cs +0 0 1 scn +/Gs1 gs +q +/DeviceRGB CS +0 0 1 SCN +/Gs2 gs +3 w +100 124.75 m +281.71 124.75 l +S +Q +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 100 670.46 Tm +/F1 30 Tf +[<486572652069732061206c696e6b21> 0] TJ +ET +Q + +endstream +endobj +11 0 obj +<< +/CreationDate (D:19700101000000Z) +/Creator (PITKIT) +/Producer (PITKIT) +>> +endobj +10 0 obj +<< +/BaseFont /Helvetica +/Encoding /WinAnsiEncoding +/Subtype /Type1 +/Type /Font +>> +endobj +2 0 obj +<< +/Pages 1 0 R +/Type /Catalog +>> +endobj +1 0 obj +<< +/Kids [5 0 R] +/Count 1 +/Type /Pages +>> +endobj +xref +0 12 +0000000000 65535 f +0000001023 00000 n +0000000974 00000 n +0000000511 00000 n +0000000382 00000 n +0000000262 00000 n +0000000015 00000 n +0000000059 00000 n +0000000114 00000 n +0000000218 00000 n +0000000876 00000 n +0000000783 00000 n +trailer +<< +/Info 11 0 R +/Root 2 0 R +/Size 12 +>> +startxref +1080 +%%EOF diff --git a/pitfall/pitfall/test/test11rkt.pdf b/pitfall/pitfall/test/test11rkt.pdf new file mode 100644 index 00000000..a34b1f05 --- /dev/null +++ b/pitfall/pitfall/test/test11rkt.pdf @@ -0,0 +1,131 @@ +%PDF-1.3 +% +6 0 obj +<< +/ca 1 +/Type /ExtGState +>> +endobj +7 0 obj +<< +/URI (http://google.com/) +/S /URI +>> +endobj +8 0 obj +<< +/A 7 0 R +/Border [0 0 0] +/Subtype /Link +/Rect [100 664.25 281.71 692] +/Type /Annot +>> +endobj +9 0 obj +<< +/CA 1 +/Type /ExtGState +>> +endobj +5 0 obj +<< +/Parent 1 0 R +/Resources 4 0 R +/Contents 3 0 R +/MediaBox [0 0 612 792] +/Annots [8 0 R] +/Type /Page +>> +endobj +4 0 obj +<< +/Font << +/F1 10 0 R +>> +/ExtGState << +/Gs2 9 0 R +/Gs1 6 0 R +>> +/ProcSet [/PDF /Text /ImageB /ImageC /ImageI] +>> +endobj +3 0 obj +<< +/Length 221 +>> +stream +1 0 0 -1 0 792 cm +/DeviceRGB cs +0 0 1 scn +/Gs1 gs +q +/DeviceRGB CS +0 0 1 SCN +/Gs2 gs +3 w +100 124.75 m +281.71 124.75 l +S +Q +q +1 0 0 -1 0 792 cm +BT +1 0 0 1 100 670.46 Tm +/F1 30 Tf +[<486572652069732061206c696e6b21> 0] TJ +ET +Q + +endstream +endobj +11 0 obj +<< +/CreationDate (D:19700101000000Z) +/Creator (PITKIT) +/Producer (PITKIT) +>> +endobj +10 0 obj +<< +/BaseFont /Helvetica +/Encoding /WinAnsiEncoding +/Subtype /Type1 +/Type /Font +>> +endobj +2 0 obj +<< +/Pages 1 0 R +/Type /Catalog +>> +endobj +1 0 obj +<< +/Kids [5 0 R] +/Count 1 +/Type /Pages +>> +endobj +xref +0 12 +0000000000 65535 f +0000001023 00000 n +0000000974 00000 n +0000000511 00000 n +0000000382 00000 n +0000000262 00000 n +0000000015 00000 n +0000000059 00000 n +0000000114 00000 n +0000000218 00000 n +0000000876 00000 n +0000000783 00000 n +trailer +<< +/Info 11 0 R +/Root 2 0 R +/Size 12 +>> +startxref +1080 +%%EOF diff --git a/pitfall/pitfall/text.rkt b/pitfall/pitfall/text.rkt index 709305b1..02016633 100644 --- a/pitfall/pitfall/text.rkt +++ b/pitfall/pitfall/text.rkt @@ -53,7 +53,8 @@ ;; word wrapping (cond - #;[(hash-ref options 'width #f) (error 'unimplemented-branch-of-_text)] ; todo + #;[(· options width) + (error 'unimplemented-branch-of-_text)] ; todo [else ; render paragraphs as single lines (for ([line (in-list (string-split text "\n"))]) (lineCallback line options))])) @@ -101,7 +102,7 @@ (define/contract (_line this text [options (mhash)] [wrapper #f]) ((string?) (hash? (or/c procedure? #f)) . ->*m . void?) (send this _fragment text (· this x) (· this y) options) - (define lineGap (or (hash-ref options 'lineGap #f) (· this _lineGap) 0)) + (define lineGap (or (· options lineGap) (· this _lineGap) 0)) (if (not wrapper) (increment-field! x this (send this widthOfString text)) (increment-field! y (+ (send this currentLineHeight #t) lineGap))) @@ -110,7 +111,6 @@ (define/contract (_fragment this text x y-in options) (string? number? number? hash? . ->m . void?) - (define align (hash-ref options 'align 'left)) (define wordSpacing (hash-ref options 'wordSpacing 0)) (define characterSpacing (hash-ref options 'characterSpacing 0)) @@ -119,7 +119,8 @@ ;; calculate the actual rendered width of the string after word and character spacing (define renderedWidth - (+ (or (· options textWidth) 0) + (+ (or (· options textWidth) + (widthOfString this text options)) (* wordSpacing (sub1 (or (· options wordCount) 0))) (* characterSpacing (sub1 (string-length text))))) @@ -132,11 +133,12 @@ (when (or (· options underline) (· options strike)) (send this save) (unless (· options stroke) - (define args (· this _fillColor)) - (send this strokeColor . args)) + (define fillColorArgs (· this _fillColor)) + (send this strokeColor . fillColorArgs)) (define lineWidth (if (< (· this _fontSize) 10) 0.5 (floor (/ (· this _fontSize) 10)))) + (send this lineWidth lineWidth) (define d (if (· options underline) 1 2)) (define lineY (+ y-in (/ (· this currentLineHeight) d))) (when (· options underline)