File: Text.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 (111 lines) | stat: -rw-r--r-- 3,280 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
.. default-domain:: js

.. highlight:: javascript

Text
====

A Text object contains text. See the `Device.prototype.fillText`.

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

.. class:: Text()

	Create a new empty text object.

	.. code-block::

		var text = new mupdf.Text()

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

.. method:: Text.prototype.getBounds(strokeState, transform)

	Get the bounds of the instance.

	:param StrokeState strokeState: The stroking state.
	:param Matrix transform: The transformation matrix.

.. method:: Text.prototype.showGlyph(font, trm, gid, uni, wmode)

	Add a glyph to the text object.

	Transform is the text matrix, specifying font size and glyph location.
	For example: ``[size, 0, 0, -size, x, y]``.

	Glyph and unicode may be ``-1`` for n-to-m cluster mappings. For
	example, the "fi" ligature would be added in two steps: first the glyph
	for the 'fi' ligature and the unicode value for 'f'; then glyph ``-1``
	and the unicode value for 'i'.

	:param Font font: Font object.
	:param Matrix trm: Transformation matrix.
	:param number gid: Glyph id.
	:param number uni: Unicode codepoint.
	:param number wmode: ``0`` (default) for horizontal writing, and ``1`` for vertical writing.

	.. code-block::

		text.showGlyph(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, 21, 0x66, 0)
		text.showGlyph(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, -1, 0x69, 0)

.. method:: Text.prototype.showString(font, trm, str, wmode)

	Add a simple string to this Text object. Will do font substitution if the font does not have all the unicode characters required.

	:param Font font: Font object.
	:param Matrix trm: Transformation matrix.
	:param string str: Content for Text object.
	:param number wmode: ``0`` (default) for horizontal writing, and ``1`` for vertical writing.

	.. code-block::

		text.showString(new mupdf.Font("Times-Roman"), mupdf.Matrix.identity, "Hello World")

.. method:: Text.prototype.walk(walker)

	:param TextWalker walker: Function with protocol methods, see example below for details.

	.. code-block::

		function print(...args) {
			console.log(args.join(" "))
		}

		var textPrinter = {
			beginSpan: function (f, m, wmode, bidi, dir, lang) {
				print("beginSpan", f, m, wmode, bidi, dir, Q(lang))
			},
			showGlyph: function (f, m, g, u, v, b) { print("glyph", f, m, g, String.fromCodePoint(u), v, b) },
			endSpan: function () { print("endSpan") }
		}

		var traceDevice = {
			fillText: function (text, ctm, colorSpace, color, alpha) {
				print("fillText", ctm, colorSpace, color, alpha)
				text.walk(textPrinter)
			},
			clipText: function (text, ctm) {
				print("clipText", ctm)
				text.walk(textPrinter)
			},
			strokeText: function (text, stroke, ctm, colorSpace, color, alpha) {
				print("strokeText", Q(stroke), ctm, colorSpace, color, alpha)
				text.walk(textPrinter)
			},
			clipStrokeText: function (text, stroke, ctm) {
				print("clipStrokeText", Q(stroke), ctm)
				text.walk(textPrinter)
			},
			ignoreText: function (text, ctm) {
				print("ignoreText", ctm)
				text.walk(textPrinter)
			}
		}

		var doc = mupdf.PDFDocument.openDocument(fs.readFileSync("test.pdf"), "application/pdf")
		var page = doc.loadPage(0)
		var device = new mupdf.Device(traceDevice)
		page.run(device, mupdf.Matrix.identity)