|
|
DescriptionAdd ly:get-font-format to get the font format
Most of the OpenType/CFF Collection (OTC) fonts
have the extension `*.ttc'.
TrueType Collection (TTC) fonts
also have the same extension `*.ttc'.
However, it is necessary that different embed method,
between OTC and TTC.
So we need to distinguish them.
This commit adds ly:get-font-format
that can get font format for distinguishing them.
Patch Set 1 #
Total comments: 1
Patch Set 2 : Use symbol instead of string #MessagesTotal messages: 9
You were faster than me :-)
LGTM, but note that FreeType's `FT_Get_Font_Format` doesn't really return the
font format but the name of the module used to handle a font. In particular, it
doesn't make a difference between PFA and PFB.
While I haven't started coding yet, I've played around to write a documentation
string first. Here is what I cooked up yesterday.
LY_DEFINE (ly_font_format_for_conversion, "ly:font-format-for-conversion",
1, 0, 0,
(SCM font_file_name),
"Return the font format of the font file as a symbol, indicating"
" how to convert it to a resource that can be embedded into a"
" PostScript output file as created by LilyPond. Possible values"
" are @code{'TrueType}, @code{'PFA}, @code{'PFB}, @code{'Type42},"
" @code{'CID}, @code{'CFF}, and @code{'OTF}. If the font format"
" is not recognized or not supported, @code{'()} gets returned.\n"
"\n"
"Fonts tagged as @code{'TrueType} can be converted to a"
" PostScript Type@tie{}42 font resource with function"
" @code{ly:ttf->pfa}. @code{'PFB} is a binary Type@tie{}1 font"
" that must be converted to a Type@tie{}1 font resource with"
" function @code{ly:pfb->pfa}. @code{'OTF} indicates a CFF"
" contained in an SFNT wrapper; it should be converted to a bare"
" CFF with function @code{ly:otf->cff}.\n"
"\n"
"Bare CFFs (tagged as @code{'CFF}) should be converted to an"
" embeddable resource with function @code{ps-embed-cff}. ASCII"
" Type@tie{}1 fonts (tagged as @code{'PFA}) should be converted"
" to embeddable resources with function @code{embed-document}."
"\n"
"Bare CID and Type@tie{}42 font resources (tagged as @code{'CID}"
" and @code{'Type42}, respectively) can be directly embedded"
" into the output.")
Such a function could be then used to rewrite `font-file-as-ps-string` to avoid
any dependency on the file extension.
https://codereview.appspot.com/296350043/diff/1/lily/open-type-font-scheme.cc
File lily/open-type-font-scheme.cc (right):
https://codereview.appspot.com/296350043/diff/1/lily/open-type-font-scheme.cc...
lily/open-type-font-scheme.cc:133: " returning it as a string. The optional"
Wouldn't it be better to return a symbol instead?
Sign in to reply to this message.
Use symbol instead of string
Sign in to reply to this message.
> LGTM, but note that FreeType's `FT_Get_Font_Format` doesn't really return the
> font format but the name of the module used to handle a font. In particular,
it
> doesn't make a difference between PFA and PFB.
My main purpose was the distinction between the TTC and OTC.
So this patch cannot distinguish between the PFA and PFB.
> Such a function could be then used to rewrite `font-file-as-ps-string` to
avoid
> any dependency on the file extension.
I'm trying the following `font-file-as-ps-string' with this Patch Set 2.
```
(define (font-file-as-ps-string name file-name font-index)
(let* ((downcase-file-name (string-downcase file-name)))
(cond
((and file-name (string-endswith downcase-file-name ".pfa"))
(embed-document file-name))
((and file-name (string-endswith downcase-file-name ".pfb"))
(ly:pfb->pfa file-name))
((and file-name (string-endswith downcase-file-name ".ttf"))
(ly:ttf->pfa file-name))
((and file-name (string-endswith downcase-file-name ".ttc"))
;; TODO: distinguish files which have extension `*.ttc'
;; whether TrueType Collection (TTC) fonts
;; or OpenType/CFF Collection (OTC) fonts.
(ly:ttf->pfa file-name font-index)) ;; TTC fonts
((and file-name (string-endswith downcase-file-name ".otf"))
(ps-embed-cff (ly:otf->cff file-name) name 0))
((and file-name (string-endswith downcase-file-name ".otc"))
;; The files which have the extension `*.otc' are OTC fonts.
(ps-embed-cff (ly:otf->cff file-name font-index) name 0)) ;; OTC fonts
(else
(ly:warning (_ "do not know how to embed ~S=~S") name file-name)
""))))
```
> Wouldn't it be better to return a symbol instead?
I've uploaded Patch Set 2 that uses a symbol instead of a string.
Sign in to reply to this message.
> My main purpose was the distinction between the TTC and OTC. > So this patch cannot distinguish between the PFA and PFB. OK, but IMHO we should get rid of being dependent on the file name suffix. > I'm trying the following `font-file-as-ps-string' with this > Patch Set 2. Hmm, this looks like the original, unpatched code...
Sign in to reply to this message.
> > My main purpose was the distinction between the TTC and OTC.
> > So this patch cannot distinguish between the PFA and PFB.
>
> OK, but IMHO we should get rid of being dependent on the file
> name suffix.
OK.
I have some PFA, PFB, TTF, TTC, OTF, OTC fonts.
FT_Get_Font_Format returns the follwing:
"Type 1" for PFA and PFB.
"TrueType" for TTF and TTC.
"CFF" for OTF and OTC.
It does not seem difficult that determine whether PFA or PFB.
Like this:
if (first_byte == 0x80)
PFB (ly:pfb->pfa ...);
else
PFA (embed-document ...);
TTF and TTC can be used same embedding way (ly:ttf->pfa ...).
OTF and OTC can be used same embedding way (ps-embed-cff (ly:otf->cff ...)).
I think that it is enough for embedding fonts without file name suffix.
But, I don't have Type42, bare-CID, bare-CFF fonts.
Are these would be necessary?
> > I'm trying the following `font-file-as-ps-string' with this
> > Patch Set 2.
>
> Hmm, this looks like the original, unpatched code...
Sorry. Here is.
```
(define (font-file-as-ps-string name file-name font-index)
(let* ((downcase-file-name (string-downcase file-name)))
(cond
((and file-name (string-endswith downcase-file-name ".pfa"))
(embed-document file-name))
((and file-name (string-endswith downcase-file-name ".pfb"))
(ly:pfb->pfa file-name))
((and file-name (string-endswith downcase-file-name ".ttf"))
(ly:ttf->pfa file-name))
((and file-name (string-endswith downcase-file-name ".ttc"))
;; Distinguish files which have extension `*.ttc'
;; whether TrueType Collection (TTC) fonts
;; or OpenType/CFF Collection (OTC) fonts.
(let* ((font-format (ly:get-font-format file-name font-index)))
(cond
((eq? font-format 'TrueType) ;; TTC fonts
(ly:ttf->pfa file-name font-index))
((eq? font-format 'CFF) ;; OTC fonts
(ps-embed-cff (ly:otf->cff file-name font-index) name 0))
(else
(ly:warning (_ "do not know how to embed ~S=~S")
name file-name)))))
((and file-name (string-endswith downcase-file-name ".otf"))
(ps-embed-cff (ly:otf->cff file-name) name 0))
((and file-name (string-endswith downcase-file-name ".otc"))
;; The files which have the extension `*.otc' are OTC fonts.
(ps-embed-cff (ly:otf->cff file-name font-index) name 0)) ;; OTC fonts
(else
(ly:warning (_ "do not know how to embed ~S=~S") name file-name)
""))))
```
Sign in to reply to this message.
> It does not seem difficult that determine whether PFA or PFB. > Like this: > if (first_byte == 0x80) > PFB (ly:pfb->pfa ...); > else > PFA (embed-document ...); I have an idea. Rewriting `ly:pfb->pfa' to `ly:type1->pfa'. For PFA fonts, it passes through the PFA. For PFB fonts, it converts the PFB to PFA. It is not necessary that rewriting `ly:get-font-format' in this Patch Set 2.
Sign in to reply to this message.
> Rewriting `ly:pfb->pfa' to `ly:type1->pfa'. > For PFA fonts, it passes through the PFA. > For PFB fonts, it converts the PFB to PFA. This certainly works.
Sign in to reply to this message.
On 2016/06/07 04:07:49, lemzwerg wrote: > > Rewriting `ly:pfb->pfa' to `ly:type1->pfa'. > > For PFA fonts, it passes through the PFA. > > For PFB fonts, it converts the PFB to PFA. > > This certainly works. I've uploaded it. https://sourceforge.net/p/testlilyissues/issues/4889/ https://codereview.appspot.com/293710043/
Sign in to reply to this message.
|
