This source file includes following definitions.
- textExtents1
- textExtents
- hasChar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.gnu.emacs;
21
22 import android.graphics.Paint;
23 import android.graphics.Rect;
24
25 public final class EmacsSdk23FontDriver extends EmacsSdk7FontDriver
26 {
27 private void
28 textExtents1 (Sdk7FontObject font, int code, FontMetrics metrics,
29 Paint paint, Rect bounds)
30 {
31 char[] text;
32
33 text = new char[2];
34 text[0] = (char) code;
35 text[1] = 'c';
36
37 paint.getTextBounds (text, 0, 1, bounds);
38
39 metrics.lbearing = (short) bounds.left;
40 metrics.rbearing = (short) bounds.right;
41 metrics.ascent = (short) -bounds.top;
42 metrics.descent = (short) bounds.bottom;
43 metrics.width
44 = (short) paint.getRunAdvance (text, 0, 1, 0, 1, false, 1);
45 }
46
47 @Override
48 public void
49 textExtents (FontObject font, int code[], FontMetrics fontMetrics)
50 {
51 int i;
52 Paint paintCache;
53 Rect boundsCache;
54 Sdk7FontObject fontObject;
55 char[] text;
56 float width;
57
58 fontObject = (Sdk7FontObject) font;
59 paintCache = fontObject.typeface.typefacePaint;
60 paintCache.setTextSize (fontObject.pixelSize);
61 boundsCache = new Rect ();
62
63 if (code.length == 0)
64 {
65 fontMetrics.lbearing = 0;
66 fontMetrics.rbearing = 0;
67 fontMetrics.ascent = 0;
68 fontMetrics.descent = 0;
69 fontMetrics.width = 0;
70 }
71 else if (code.length == 1)
72 textExtents1 ((Sdk7FontObject) font, code[0], fontMetrics,
73 paintCache, boundsCache);
74 else
75 {
76 text = new char[code.length + 1];
77
78 for (i = 0; i < code.length; ++i)
79 text[i] = (char) code[i];
80
81 text[code.length] = 'c';
82
83 paintCache.getTextBounds (text, 0, code.length,
84 boundsCache);
85 width = paintCache.getRunAdvance (text, 0, code.length, 0,
86 code.length,
87 false, code.length);
88
89 fontMetrics.lbearing = (short) boundsCache.left;
90 fontMetrics.rbearing = (short) boundsCache.right;
91 fontMetrics.ascent = (short) -boundsCache.top;
92 fontMetrics.descent = (short) boundsCache.bottom;
93 fontMetrics.width = (short) width;
94 }
95 }
96
97 @Override
98 public int
99 hasChar (FontSpec font, char charCode)
100 {
101 Sdk7FontObject fontObject;
102 Paint paint;
103
104 if (font instanceof Sdk7FontObject)
105 {
106 fontObject = (Sdk7FontObject) font;
107 paint = fontObject.typeface.typefacePaint;
108 }
109 else
110 paint = ((Sdk7FontEntity) font).typeface.typefacePaint;
111
112 return paint.hasGlyph (String.valueOf (charCode)) ? 1 : 0;
113 }
114 };