Commit 2b5d14409422540182cde7d99b56f2a412b23f02

henry 2003-01-13T03:09:33

Integrating ICU

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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
diff --git a/extras/layout/FTICUFace.cpp b/extras/layout/FTICUFace.cpp
new file mode 100644
index 0000000..75df663
--- /dev/null
+++ b/extras/layout/FTICUFace.cpp
@@ -0,0 +1,124 @@
+#include <cassert>
+
+#include "FTICUFace.h"
+
+
+FTICUFace::FTICUFace( const char* filename)
+:   face( filename)
+{
+    err = face.Error();
+}
+
+
+FTICUFace::FTICUFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
+:   face( pBufferBytes, bufferSizeInBytes)
+{
+    err = face.Error();
+}
+
+FTICUFace::~FTICUFace()
+{}
+
+
+const void* FTICUFace::getFontTable( LETag tableTag) const
+{
+    assert( false);
+}
+
+le_bool FTICUFace::canDisplay( LEUnicode32 ch) const
+{
+    assert( false);
+}
+
+        
+le_int32 FTICUFace::getUnitsPerEM() const
+{
+    return face.UnitsPerEM();
+}
+        
+void FTICUFace::mapCharsToGlyphs( const LEUnicode chars[], le_int32 offset,
+                                  le_int32 count, le_bool reverse, const LECharMapper *mapper,
+                                  LEGlyphID glyphs[]) const
+{
+    assert( false);
+}
+
+        
+LEGlyphID FTICUFace::mapCharToGlyph( LEUnicode32 ch, const LECharMapper *mapper) const
+{
+    assert( false);
+}
+
+        
+le_int32 FTICUFace::getName( le_uint16 platformID, le_uint16 scriptID, le_uint16 languageID,
+                             le_uint16 nameID, LEUnicode *name) const
+{
+    assert( false);
+}
+
+        
+void FTICUFace::getGlyphAdvance( LEGlyphID glyph, LEPoint &advance) const
+{
+    assert( false);
+}
+
+        
+le_bool FTICUFace::getGlyphPoint( LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const
+{
+    assert( false);
+}
+
+        
+float FTICUFace::getXPixelsPerEm() const
+{
+    assert( false);
+}
+
+        
+float FTICUFace::getYPixelsPerEm() const
+{
+    assert( false);
+}
+
+        
+float FTICUFace::xUnitsToPoints( float xUnits) const
+{
+    assert( false);
+}
+
+        
+float FTICUFace::yUnitsToPoints( float yUunits) const
+{
+    assert( false);
+}
+
+        
+void FTICUFace::unitsToPoints( LEPoint &units, LEPoint &points) const
+{
+    assert( false);
+}
+
+        
+float FTICUFace::xPixelsToUnits( float xPixels) const
+{
+    assert( false);
+}
+
+        
+float FTICUFace::yPixelsToUnits( float yPixels) const
+{
+    assert( false);
+}
+
+        
+void FTICUFace::pixelsToUnits( LEPoint &pixels, LEPoint &units) const
+{
+    assert( false);
+}
+
+        
+void FTICUFace::transformFunits( float xFunits, float yFunits, LEPoint &pixels) const
+{
+    assert( false);
+}
+
diff --git a/extras/layout/FTICUFace.h b/extras/layout/FTICUFace.h
index b815fe7..f66a3f0 100644
--- a/extras/layout/FTICUFace.h
+++ b/extras/layout/FTICUFace.h
@@ -1,14 +1,54 @@
 #include "FTFace.h"
+#include "LEFontInstance.h"
 
 
 class FTICUFace : public LEFontInstance
 {
     public:
-        FTICUFace(){}
+        FTICUFace( const char* filename);
+
+        FTICUFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
+        
+        ~FTICUFace();
+        
+        virtual const void *getFontTable(LETag tableTag) const;
+        
+        virtual le_bool canDisplay(LEUnicode32 ch) const;
+        
+        virtual le_int32 getUnitsPerEM() const;
+        
+        virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, const LECharMapper *mapper, LEGlyphID glyphs[]) const;
+        
+        virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;
+        
+        virtual le_int32 getName(le_uint16 platformID, le_uint16 scriptID, le_uint16 languageID, le_uint16 nameID, LEUnicode *name) const;
+        
+        virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
+        
+        virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const;
         
-        ~FTICUFace(){}
+        virtual float getXPixelsPerEm() const;
         
-    private;
+        virtual float getYPixelsPerEm() const;
+        
+        virtual float xUnitsToPoints(float xUnits) const;
+        
+        virtual float yUnitsToPoints(float yUunits) const;
+        
+        virtual void unitsToPoints(LEPoint &units, LEPoint &points) const;
+        
+        virtual float xPixelsToUnits(float xPixels) const;
+        
+        virtual float yPixelsToUnits(float yPixels) const;
+        
+        virtual void pixelsToUnits(LEPoint &pixels, LEPoint &units) const;
+        
+        virtual void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const;
+        
+        FT_Error Error() const { return err;}
+
+    private:
         FTFace face;
+        FT_Error err;
 
 };
\ No newline at end of file
diff --git a/extras/layout/FTLayoutFont.cpp b/extras/layout/FTLayoutFont.cpp
new file mode 100644
index 0000000..a4fe91b
--- /dev/null
+++ b/extras/layout/FTLayoutFont.cpp
@@ -0,0 +1,17 @@
+#include "LayoutEngine.h"
+#include "FTLayoutFont.h"
+
+FTLayoutFont::FTLayoutFont( const char* fontname, int script)
+:   face( fontname)
+{
+    err = face.Error();
+    LEErrorCode success;
+    
+    layoutEngine = LayoutEngine::layoutEngineFactory( &face,
+                                                      (le_int32) script,
+                                                      0,
+                                                      (LEErrorCode &) success);
+
+}
+        
+        
diff --git a/extras/layout/FTLayoutFont.h b/extras/layout/FTLayoutFont.h
index 11c1e50..38be4d1 100644
--- a/extras/layout/FTLayoutFont.h
+++ b/extras/layout/FTLayoutFont.h
@@ -1,11 +1,25 @@
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include "FTICUFace.h"
+
+namespace icu_2_4
+{
+    class LayoutEngine;
+}
+
 class FTLayoutFont
 {
     public:
-        FTLayoutFont(){}
+        FTLayoutFont( const char* fontname, int script);
         
-        ~FTLayoutFont(){}
+        FT_Error Error() const { return err;}
         
     private:
-        FTICUFace* face;
+        FTICUFace face;
+        
+        LayoutEngine* layoutEngine;
+        
+        FT_Error err;
 
 };
\ No newline at end of file
diff --git a/extras/layout/LEFontInstance.h b/extras/layout/LEFontInstance.h
new file mode 100644
index 0000000..1d88b5f
--- /dev/null
+++ b/extras/layout/LEFontInstance.h
@@ -0,0 +1,314 @@
+
+/*
+ * @(#)LEFontInstance.h	1.3 00/03/15
+ *
+ * (C) Copyright IBM Corp. 1998, 1999, 2000, 2001, 2002 - All Rights Reserved
+ *
+ */
+
+#ifndef __LEFONTINSTANCE_H
+#define __LEFONTINSTANCE_H
+
+#include "LETypes.h"
+
+U_NAMESPACE_BEGIN
+
+/**
+ * Instances of this class are used by LEFontInstance::mapCharsToGlyphs and
+ * LEFontInstance::mapCharToGlyph to adjust character codes before the character
+ * to glyph mapping process. Examples of this are filtering out control charcters
+ * and character mirroring - replacing a character which has both a left and a right
+ * hand form with the opposite form.
+ *
+ * @draft ICU 2.2
+ */
+class LECharMapper /* not : public UObject because this is an interface/mixin class */ {
+public:
+    /**
+     * Destructor.
+     * @draft ICU 2.4
+     */
+    virtual inline ~LECharMapper() {};
+
+    /**
+     * This method does the adjustments.
+     *
+     * @param ch - the input charcter
+     *
+     * @return the adjusted character
+     *
+     * @draft ICU 2.2
+     */
+    virtual LEUnicode32 mapChar(LEUnicode32 ch) const = 0;
+};
+
+/**
+ * This is a pure virtual base class that servers as the interface between a LayoutEngine
+ * and the platform font environment. It allows a LayoutEngine to access font tables, do
+ * character to glyph mapping, and obtain metrics information without knowing any platform
+ * specific details. There are also a few utility methods for converting between points,
+ * pixels and funits. (font design units)
+ *
+ * Each instance of an LEFontInstance represents a renerable instance of a font. (i.e. a
+ * single font at a particular point size, with a particular transform)
+ *
+ * @draft ICU 2.2
+ */
+class LEFontInstance /* not : public UObject because this is an interface/mixin class */ {
+public:
+
+    /**
+     * This virtual destructor is here so that the subclass
+     * destructors can be invoked through the base class.
+     *
+     * @draft ICU 2.2
+     */
+    virtual inline ~LEFontInstance() {};
+
+    //
+    // Font file access
+    //
+
+    /**
+     * This method reads a table from the font.
+     *
+     * @param tableTag - the four byte table tag
+     *
+     * @return the address of the table in memory
+     *
+     * @draft ICU 2.2
+     */
+    virtual const void *getFontTable(LETag tableTag) const = 0;
+
+    /**
+     * This method is used to determine if the font can
+     * render the given character. This can usually be done
+     * by looking the character up in the font's character
+     * to glyph mapping.
+     *
+     * @param ch - the character to be tested
+     *
+     * @return true if the font can render ch.
+     *
+     * @draft ICU 2.2
+     */
+    virtual le_bool canDisplay(LEUnicode32 ch) const = 0;
+
+    /**
+     * This method returns the number of design units in
+     * the font's EM square.
+     *
+     * @return the number of design units pre EM.
+     *
+     * @draft ICU 2.2
+     */
+    virtual le_int32 getUnitsPerEM() const = 0;
+
+    /**
+     * This method maps an array of charcter codes to an array of glyph
+     * indices, using the font's character to glyph map.
+     *
+     * @param chars - the character array
+     * @param offset - the index of the first charcter
+     * @param count - the number of charcters
+     * @param reverse - if true, store the glyph indices in reverse order.
+     * @param mapper - the character mapper.
+     * @param glyphs - the output glyph array
+     *
+     * @see LECharMapper
+     *
+     * @draft ICU 2.2
+     */
+    virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, const LECharMapper *mapper, LEGlyphID glyphs[]) const = 0;
+
+    /**
+     * This method maps a single character to a glyph index, using the
+     * font's charcter to glyph map.
+     *
+     * @param ch - the character
+     * @param mapper - the character mapper
+     *
+     * @return the glyph index
+     *
+     * @see LECharMapper
+     *
+     * @draft ICU 2.2
+     */
+    virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const = 0;
+
+    /**
+     * This method gets a name from the font. (e.g. the family name) The encoding
+     * of the name is specified by the platform, the script, and the language.
+     *
+     * @param platformID - the platform id
+     * @param scriptID - the script id
+     * @param langaugeID - the language id
+     * @param name - the destination character array (can be null)
+     *
+     * @return the number of characters in the name
+     *
+     * @draft ICU 2.2
+     */
+    virtual le_int32 getName(le_uint16 platformID, le_uint16 scriptID, le_uint16 languageID, le_uint16 nameID, LEUnicode *name) const = 0;
+
+    //
+    // Metrics
+    //
+
+    /**
+     * This method gets the X and Y advance of a particular glyph, in pixels.
+     *
+     * @param glyph - the glyph index
+     * @param advance - the X and Y pixel values will be stored here
+     *
+     * @draft ICU 2.2
+     */
+    virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const = 0;
+
+    /**
+     * This method gets the hinted X and Y pixel coordinates of a particular
+     * point in the outline of the given glyph.
+     *
+     * @param glyph - the glyph index
+     * @param pointNumber - the number of the point
+     * @param point - the point's X and Y pixel values will be stored here
+     *
+     * @return true if the point coordinates could be stored.
+     *
+     * @draft ICU 2.2
+     */
+    virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const = 0;
+
+    /**
+     * This method returns the width of the font's EM square
+     * in pixels.
+     *
+     * @return the pixel width of the EM square
+     *
+     * @draft ICU 2.2
+     */
+    virtual float getXPixelsPerEm() const = 0;
+
+    /**
+     * This method returns the height of the font's EM square
+     * in pixels.
+     *
+     * @return the pixel height of the EM square
+     *
+     * @draft ICU 2.2
+     */
+    virtual float getYPixelsPerEm() const = 0;
+
+    /**
+     * This method converts font design units in the
+     * X direction to points.
+     *
+     * @param xUnits - design units in the X direction
+     *
+     * @return points in the X direction
+     *
+     * @draft ICU 2.2
+     */
+    virtual float xUnitsToPoints(float xUnits) const = 0;
+
+    /**
+     * This method converts font design units in the
+     * Y direction to points.
+     *
+     * @param yUnits - design units in the Y direction
+     *
+     * @return points in the Y direction
+     *
+     * @draft ICU 2.2
+     */
+    virtual float yUnitsToPoints(float yUunits) const = 0;
+
+    /**
+     * This method converts font design units to points.
+     *
+     * @param units - X and Y design units
+     * @param points - set to X and Y points
+     *
+     * @draft ICU 2.2
+     */
+    virtual void unitsToPoints(LEPoint &units, LEPoint &points) const = 0;
+
+    /**
+     * This method converts pixels in the
+     * X direction to font design units.
+     *
+     * @param xPixels - pixels in the X direction
+     *
+     * @return font design units in the X direction
+     *
+     * @draft ICU 2.2
+     */
+    virtual float xPixelsToUnits(float xPixels) const = 0;
+
+    /**
+     * This method converts pixels in the
+     * Y direction to font design units.
+     *
+     * @param yPixels - pixels in the Y direction
+     *
+     * @return font design units in the Y direction
+     *
+     * @draft ICU 2.2
+     */
+    virtual float yPixelsToUnits(float yPixels) const = 0;
+
+    /**
+     * This method converts pixels to font design units.
+     *
+     * @param pixels - X and Y pixel
+     * @param units - set to X and Y font design units
+     *
+     * @draft ICU 2.2
+     */
+    virtual void pixelsToUnits(LEPoint &pixels, LEPoint &units) const = 0;
+
+    /**
+     * This method transforms an X, Y point in font design units to a
+     * pixel coordinate, applying the font's transform.
+     *
+     * @param xFunits - the X coordinate in font design units
+     * @param yFunits - the Y coordinate in font design units
+     * @param pixels - the tranformed co-ordinate in pixels
+     *
+     * @draft ICU 2.2
+     */
+    virtual void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const = 0;
+
+    /**
+     * This is a convenience method used to convert
+     * values in a 16.16 fixed point format to floating point.
+     *
+     * @param fixed - the fixed point value
+     *
+     * @return the floating point value
+     *
+     * @draft ICU 2.2
+     */
+    static float fixedToFloat(le_int32 fixed)
+    {
+        return (float) (fixed / 65536.0);
+    };
+
+    /**
+     * This is a convenience method used to convert
+     * floating point values to 16.16 fixed point format.
+     *
+     * @param theFloat - the floating point value
+     *
+     * @return the fixed point value
+     */
+    static le_int32 floatToFixed(float theFloat)
+    {
+        return (le_int32) (theFloat * 65536.0);
+    };
+};
+
+U_NAMESPACE_END
+#endif
+
+
diff --git a/test/FTlayout-Test.cpp b/test/FTlayout-Test.cpp
index 2804ae4..880469b 100755
--- a/test/FTlayout-Test.cpp
+++ b/test/FTlayout-Test.cpp
@@ -3,7 +3,10 @@
 #include <cppunit/TestCase.h>
 #include <cppunit/TestSuite.h>
 
+#include "Fontdefs.h"
+#include "layout/FTLayoutFont.h"
 
+static const int SCRIPT = 2; // arabic
 
 class FTLayoutTest : public CppUnit::TestCase
 {
@@ -19,6 +22,8 @@ class FTLayoutTest : public CppUnit::TestCase
 
         void testConstructor()
         {
+            FTLayoutFont font( FONT_FILE, SCRIPT);
+            CPPUNIT_ASSERT( font.Error() == 0);
         }
         
         void setUp()