File: Font.rst

package info (click to toggle)
mupdf 1.27.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,224 kB
  • sloc: ansic: 335,320; python: 20,906; java: 7,520; javascript: 2,213; makefile: 1,152; xml: 675; cpp: 639; sh: 513; cs: 307; awk: 10; sed: 7; lisp: 3
file content (148 lines) | stat: -rw-r--r-- 3,229 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
.. default-domain:: js

.. highlight:: javascript

Font
====

Font objects can be created from TrueType, OpenType,
Type1 or CFF fonts. In PDF there are also special
Type3 fonts.

Constructors
------------

.. class::
	Font(name, data, index)
	Font(name, filename, index)

	Create a new font. Either from a buffer, a file name, or a
	built-in font name.

	The built-in standard PDF fonts are:

	- ``"Times-Roman"``
	- ``"Times-Italic"``
	- ``"Times-Bold"``
	- ``"Times-BoldItalic"``
	- ``"Helvetica"``
	- ``"Helvetica-Oblique"``
	- ``"Helvetica-Bold"``
	- ``"Helvetica-BoldOblique"``
	- ``"Courier"``
	- ``"Courier-Oblique"``
	- ``"Courier-Bold"``
	- ``"Courier-BoldOblique"``
	- ``"Symbol"``
	- ``"ZapfDingbats"``

	The built-in CJK fonts are referenced by language code:
	``"zh-Hant"``, ``"zh-Hans"``, ``"ja"``, ``"ko"``.

	:param string name: Font name.
	:param Buffer | ArrayBuffer | Uint8Array data: The font data if loaded from a buffer.
	:param string filename: The name of the font file to load.
	:param number index: Subfont index (only used for TTC fonts).

	.. code-block::

		var font1 = new mupdf.Font("Times-Roman")
		var font2 = new mupdf.Font("ko")
                var font3 = new mupdf.Font("Comic Sans", "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf")
                var font4 = new mupdf.Font("Comic Sans", "/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", 1)
		var font5 = new mupdf.Font("Freight Sans", fs.readFileSync("DroidSansFallbackFull.ttf"))

Constants
---------

Encoding constants for `PDFDocument.prototype.addSimpleFont`:

.. data:: Font.SIMPLE_ENCODING_LATIN

	WinAnsiEncoding (a.k.a. CP-1252)

.. data:: Font.SIMPLE_ENCODING_GREEK

	ISO-8859-7

.. data:: Font.SIMPLE_ENCODING_CYRILLIC

	KOI8-U

Instance methods
----------------

.. method:: Font.prototype.getName()

	Get the font name.

	:returns: string

	.. code-block::

		var name = font.getName()

.. method:: Font.prototype.encodeCharacter(unicode)

	Get the glyph index for a unicode character. Glyph ``0`` is returned if the font does not have a glyph for the character.

	:param number | string unicode: The unicode character, or the first unicode character of a string.

	:returns: number.

	.. code-block::

		var index = font.encodeCharacter(0x42)

.. method:: Font.prototype.advanceGlyph(glyph , wmode)

	Return advance width for a glyph in either horizontal or vertical writing mode.

	:param number glyph: The glyph as unicode character.
	:param number wmode: ``0`` for horizontal writing, and ``1`` for vertical writing, defaults to horizontal.

	:returns: number

	.. code-block::

		var width = font.advanceGlyph(0x42)

.. method:: Font.prototype.isBold()

	Returns ``true`` if font is bold.

	:returns: boolean

	.. code-block::

		var isBold = font.isBold()

.. method:: Font.prototype.isItalic()

	Returns ``true`` if font is italic.

	:returns: boolean

	.. code-block::

		var isItalic = font.isItalic()

.. method:: Font.prototype.isMono()

	Returns ``true`` if font is monospaced.

	:returns: boolean

	.. code-block::

		var isMono = font.isMono()

.. method:: Font.prototype.isSerif()

	Returns ``true`` if font is serif.

	:returns: boolean

	.. code-block::

		var isSerif = font.isSerif()