问题
I have this problem across my mind, any help will be appreciated. Is there are PHP function, or library that can extract some glyphs form a font file?
Edit: By means to extract some glyphs, I wanted to create a new font file based on the glyphs extracted (so it has smaller bytes), or just get the glyphs and create base64 encoded font data from it so I can embed it via @font-face. I just wanted to get rid glyphs that has no use so CSS (base64) or font file will be loaded faster.
回答1:
I can understand your question two ways. Either you want to pull the image out of the font file directly, or you want to print with that font as text in an image.
But both have the same answer:
Try GD or ImageMagick to pull the image of a glyph from a font file using the font to print that character into the image. Don't open the font like an image, use the font as it was intended. You can then print the glyph at whatever size you want and use it however you want.
回答2:
You are trying to make a subset font aren't you? This problem have been investigated heavily by the embedded font community.
Even that, there is not definite answer here. Last time I checked people write Perl/C programs to extract binary data from font files, based on TTF/OTF spec.
If you are using Latin font, don't brother coz it's small enough. If you are using CJK font like me, FontForge could help you copy and paste the gryphs by hand. Other than that you need to write a script/program by yourself.
回答3:
I did it once using python : Here is the code snippet
def get_pdf_fontobjects(self, ):
pdffile = self.pdffile
pdf_font_objects = []
p = subprocess.Popen(["pdffonts", pdffile], shell=False, stdout=subprocess.PIPE)
for line in p.stdout:
line = line.strip()
g = re.search("^(\S+)\s.+?yes\s+(\d+)\s+(\d+)$", line)
'''if g and g.group(1) in self.fonts2process:
pdf_font_objects.append(g.group(2))'''
if g:
font_name = g.group(1)
for font_pattern in self.fonts2process:
if re.search(font_pattern, font_name):
pdf_font_objects.append(g.group(2))
return pdf_font_objects
and font2process can be a list of font names: fonts2process = ['Arial-Unicode-MS', 'Shruti', 'ArialUnicodeMS', 'TT', 'Raavi', 'SolaimanLipi', 'AnjaliOldLipi', 'Vrinda', 'Surekh', 'AAAAAB+ArialUnicodeMS', 'AAAAAG+VArialUnicodeMS', 'DNCDIV+Tunga_00', 'JGTFDM+Tunga,Bold_00', 'Latha', 'Mangal', 'Surekh', 'Gautami' ]
But working on certain font without makers permission is illegal*
来源:https://stackoverflow.com/questions/4253909/extract-font-glyphs