resume in binary structuring

main
Matthew Butterick 8 years ago
parent ebb57d3094
commit 843d6cb6d9

@ -296,7 +296,7 @@ module.exports =
for pos, i in positions
# If we have an x or y offset, we have to break out of the current TJ command
# so we can move the text position.
console.log("pos.xOffset or pos.yOffset=" + (pos.xOffset or pos.yOffset))
#console.log("pos.xOffset or pos.yOffset=" + (pos.xOffset or pos.yOffset))
if pos.xOffset or pos.yOffset
# Flush the current buffer
flush i

@ -41,7 +41,7 @@ fontkit.registerFormat = function (format) {
fontkit.openSync = function (filename, postscriptName) {
var buffer = fs.readFileSync(filename);
console.log(filename);
//console.log(filename);
return fontkit.create(buffer, postscriptName);
};
@ -12285,6 +12285,7 @@ var TTFFont = (_class = function () {
};
TTFFont.prototype._decodeDirectory = function _decodeDirectory() {
console.log("Directory.decode="+Directory.decode)
return this.directory = Directory.decode(this.stream, { _startOffset: 0 });
};

@ -0,0 +1,5 @@
#lang pitfall/racket
(provide (all-defined-out))
(define (directory-decode . xs)
'boom)

@ -59,6 +59,8 @@ For now, we'll just measure width of the characters.
(values subset-idx posn)))
(list subset-idxs new-positions))
(require racket/runtime-path)
(define-runtime-path charter-path "test/assets/charter.ttf")
(define/contract (embed this)
(->m void?)
@ -70,7 +72,7 @@ For now, we'll just measure width of the characters.
;; todo
;; (send (send (· this subset) encodeStream) pipe fontFile)
(send fontFile end) ;; temp
(send fontFile end (send (· this subset) encode)) ;; temp
;; todo
;; (define familyClass (send (· this font) has-table? #"OS/2"))
@ -107,7 +109,7 @@ For now, we'll just measure width of the characters.
'FontFile2) fontFile)
(· descriptor end)
(report (· descriptor toString) 'descriptor-id)
#;(report (· descriptor toString) 'descriptor-id)
(define descendantFont (send (· this document) ref
(mhash
@ -124,7 +126,7 @@ For now, we'll just measure width of the characters.
(hash-ref (· this widths) idx (λ () (error 'embed (format "hash key ~a not found" idx)))))))))
(· descendantFont end)
(report (· descendantFont toString) 'descendantFont)
#;(report (· descendantFont toString) 'descendantFont)
(hash-set*! (· this dictionary payload)
'Type "Font"
'Subtype "Type0"
@ -170,7 +172,7 @@ For now, we'll just measure width of the characters.
end
end
})
(report (· cmap toString) 'cmap-id)
#;(report (· cmap toString) 'cmap-id)
cmap)
(define/contract (toHex . codePoints)

@ -1,5 +1,5 @@
#lang pitfall/racket
(require "freetype-ffi.rkt" ffi/unsafe racket/runtime-path "subset.rkt" "glyph.rkt" "layout-engine.rkt" "bbox.rkt" "glyphrun.rkt" "cmap-processor.rkt")
(require "freetype-ffi.rkt" ffi/unsafe racket/runtime-path "subset.rkt" "glyph.rkt" "layout-engine.rkt" "bbox.rkt" "glyphrun.rkt" "cmap-processor.rkt" "directory.rkt")
(provide (all-defined-out))
(define-runtime-path charter-path "test/assets/charter.ttf")
@ -7,25 +7,31 @@
;; approximates
;; https://github.com/devongovett/fontkit/blob/master/src/TTFFont.js
(define-subclass object% (TTFFont filename)
;; This is the base class for all SFNT-based font formats in fontkit.
;; It supports TrueType, and PostScript glyphs, and several color glyph formats.
(define-subclass object% (TTFFont [stream (open-input-bytes #"")])
(super-new)
(field [_tables (mhash)]
(when stream (unless (input-port? stream)
(raise-argument-error 'TTFFont "input port" stream)))
(field [_directoryPos (let-values ([(l c p) (port-next-location stream)])
p)]
[_tables (mhash)]
[_glyphs (mhash)]
[_layoutEngine #f])
(field [buffer (file->bytes filename)])
(define (buffer->font buffer)
'made-ttf-font)
(field [directory #f])
(send this _decodeDirectory)
(define/public (_decodeDirectory)
(set! directory (directory-decode stream (mhash '_startOffset 0)))
directory)
(define (probe buffer)
(define/public (probe buffer)
(and
(member (bytes->string/latin-1 (subbytes buffer 0 4))
(list "true" "OTTO" "\u0\u1\u0\u0"))
'TTF-format))
(and (probe buffer) (buffer->font buffer))
(field [ft-library (FT_Init_FreeType)])
(field [ft-face (FT_New_Face ft-library charter-path 0)])
@ -224,21 +230,24 @@
;;fontkit.registerFormat(DFont); ;; todo
(define/contract (create filename [postscriptName #f])
(define/contract (openSync filename [postscriptName #f])
((string?) ((or/c string? #f)) . ->* . any/c)
(define buffer (file->bytes filename))
(create buffer postscriptName))
(define/contract (create buffer [postscriptName #f])
((bytes?) ((or/c string? #f)) . ->* . any/c)
(or
(for*/first ([format (in-list formats)]
[font (in-value (make-object format filename))]
#:when font)
#:when (send (make-object format) probe buffer))
(define font (make-object format (open-input-bytes buffer)))
(if postscriptName
(send font getFont postscriptName) ; used to select from collection files like TTC
font))
(error 'create "unknown font format")))
(define/contract (openSync filename [postscriptName #f])
((string?) ((or/c string? #f)) . ->* . any/c)
(create filename postscriptName))
(error 'fontkit:create "unknown font format")))
(module+ test

@ -14,17 +14,19 @@
(define/contract (write this x)
((or/c string? isBuffer?) . ->m . void?)
(push-field! byte-strings this (if (isBuffer? x)
x
(bytes-append (newBuffer x) #"\n"))))
((or/c string? isBuffer? input-port?) . ->m . void?)
(push-field! byte-strings this
(let loop ([x x])
(cond
[(isBuffer? x) x]
[(input-port? x) (loop (port->bytes x))]
[else (bytes-append (newBuffer x) #"\n")]))))
(define got-byte-strings? pair?)
(define/contract (end this [chunk #f])
(() ((or/c string? isBuffer?)) . ->*m . void?)
(when chunk
(send this write chunk))
(() ((or/c string? isBuffer? input-port?)) . ->*m . void?)
(when chunk (send this write chunk))
#;(report* 'end! (· this id))
(define bstrs-to-write

@ -36,4 +36,11 @@
(define-subclass Subset (TTFSubset)
(super-new)
)
(as-methods
encode)
)
(define/contract (encode this)
(->m input-port?)
(· this font stream))

Binary file not shown.

@ -13,11 +13,12 @@
[text "Some text with an embedded font" 100 100 (hash
'width #f)]))
;; test against non-subsetted font version
(define-runtime-path this "test12rkt.pdf")
(make-doc this #f proc #:test #f)
(make-doc this #f proc #:pdfkit #f)
#;(define-runtime-path that "test12crkt.pdf")
#;(make-doc that #t proc #:test #f)
(define-runtime-path that "test12crkt.pdf")
(make-doc that #t proc #:pdfkit #f)
#;(module+ test
(define doc (make-object PDFDocument))

Loading…
Cancel
Save