[icu-le] Hook up to hb_face_t
This commit is contained in:
parent
e96bb36995
commit
ba7f6c3797
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#define HB_SHAPER icu_le
|
||||
#define hb_icu_le_shaper_font_data_t PortableFontInstance
|
||||
#include "hb-shaper-impl-private.hh"
|
||||
|
||||
#include "hb-icu-le/PortableFontInstance.h"
|
||||
|
@ -61,18 +62,26 @@ _hb_icu_le_shaper_face_data_destroy (hb_icu_le_shaper_face_data_t *data)
|
|||
* shaper font data
|
||||
*/
|
||||
|
||||
struct hb_icu_le_shaper_font_data_t {};
|
||||
|
||||
hb_icu_le_shaper_font_data_t *
|
||||
_hb_icu_le_shaper_font_data_create (hb_font_t *font)
|
||||
{
|
||||
return (hb_icu_le_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
|
||||
LEErrorCode status = LE_NO_ERROR;
|
||||
hb_icu_le_shaper_font_data_t *data = new PortableFontInstance (font->face,
|
||||
font->x_scale,
|
||||
font->y_scale,
|
||||
status);
|
||||
if (status != LE_NO_ERROR) {
|
||||
delete (data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void
|
||||
_hb_icu_le_shaper_font_data_destroy (hb_icu_le_shaper_font_data_t *data)
|
||||
{
|
||||
free (data);
|
||||
delete (data);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
struct FontTableCacheEntry
|
||||
{
|
||||
LETag tag;
|
||||
const void *table;
|
||||
hb_blob_t *blob;
|
||||
};
|
||||
|
||||
FontTableCache::FontTableCache()
|
||||
|
@ -31,17 +31,17 @@ FontTableCache::FontTableCache()
|
|||
|
||||
for (int i = 0; i < fTableCacheSize; i += 1) {
|
||||
fTableCache[i].tag = 0;
|
||||
fTableCache[i].table = NULL;
|
||||
fTableCache[i].blob = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
FontTableCache::~FontTableCache()
|
||||
{
|
||||
for (int i = fTableCacheCurr - 1; i >= 0; i -= 1) {
|
||||
DELETE_ARRAY(fTableCache[i].table);
|
||||
hb_blob_destroy(fTableCache[i].blob);
|
||||
|
||||
fTableCache[i].tag = 0;
|
||||
fTableCache[i].table = NULL;
|
||||
fTableCache[i].blob = NULL;
|
||||
}
|
||||
|
||||
fTableCacheCurr = 0;
|
||||
|
@ -49,27 +49,27 @@ FontTableCache::~FontTableCache()
|
|||
DELETE_ARRAY(fTableCache);
|
||||
}
|
||||
|
||||
void FontTableCache::freeFontTable(const void *table) const
|
||||
void FontTableCache::freeFontTable(hb_blob_t *blob) const
|
||||
{
|
||||
DELETE_ARRAY(table);
|
||||
hb_blob_destroy(blob);
|
||||
}
|
||||
|
||||
const void *FontTableCache::find(LETag tableTag) const
|
||||
{
|
||||
for (int i = 0; i < fTableCacheCurr; i += 1) {
|
||||
if (fTableCache[i].tag == tableTag) {
|
||||
return fTableCache[i].table;
|
||||
return hb_blob_get_data(fTableCache[i].blob, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
const void *table = readFontTable(tableTag);
|
||||
hb_blob_t *blob = readFontTable(tableTag);
|
||||
|
||||
((FontTableCache *) this)->add(tableTag, table);
|
||||
((FontTableCache *) this)->add(tableTag, blob);
|
||||
|
||||
return table;
|
||||
return hb_blob_get_data (blob, NULL);
|
||||
}
|
||||
|
||||
void FontTableCache::add(LETag tableTag, const void *table)
|
||||
void FontTableCache::add(LETag tableTag, hb_blob_t *blob)
|
||||
{
|
||||
if (fTableCacheCurr >= fTableCacheSize) {
|
||||
le_int32 newSize = fTableCacheSize + TABLE_CACHE_GROW;
|
||||
|
@ -78,14 +78,14 @@ void FontTableCache::add(LETag tableTag, const void *table)
|
|||
|
||||
for (le_int32 i = fTableCacheSize; i < newSize; i += 1) {
|
||||
fTableCache[i].tag = 0;
|
||||
fTableCache[i].table = NULL;
|
||||
fTableCache[i].blob = NULL;
|
||||
}
|
||||
|
||||
fTableCacheSize = newSize;
|
||||
}
|
||||
|
||||
fTableCache[fTableCacheCurr].tag = tableTag;
|
||||
fTableCache[fTableCacheCurr].table = table;
|
||||
fTableCache[fTableCacheCurr].blob = blob;
|
||||
|
||||
fTableCacheCurr += 1;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
|
||||
#define __FONTTABLECACHE_H
|
||||
|
||||
#define HB_H_IN
|
||||
#include <hb-blob.h>
|
||||
|
||||
#include "layout/LETypes.h"
|
||||
|
||||
U_NAMESPACE_USE
|
||||
|
@ -25,12 +28,12 @@ public:
|
|||
const void *find(LETag tableTag) const;
|
||||
|
||||
protected:
|
||||
virtual const void *readFontTable(LETag tableTag) const = 0;
|
||||
virtual void freeFontTable(const void *table) const;
|
||||
virtual hb_blob_t *readFontTable(LETag tableTag) const = 0;
|
||||
virtual void freeFontTable(hb_blob_t *blob) const;
|
||||
|
||||
private:
|
||||
|
||||
void add(LETag tableTag, const void *table);
|
||||
void add(LETag tableTag, hb_blob_t *blob);
|
||||
|
||||
FontTableCacheEntry *fTableCache;
|
||||
le_int32 fTableCacheCurr;
|
||||
|
|
|
@ -64,83 +64,24 @@ le_int8 PortableFontInstance::highBit(le_int32 value)
|
|||
return bit;
|
||||
}
|
||||
|
||||
PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize, LEErrorCode &status)
|
||||
: fFile(NULL), fPointSize(pointSize), fUnitsPerEM(0), fFontChecksum(0), fAscent(0), fDescent(0), fLeading(0),
|
||||
fDirectory(NULL), fNAMETable(NULL), fNameCount(0), fNameStringOffset(0), fCMAPMapper(NULL), fHMTXTable(NULL), fNumGlyphs(0), fNumLongHorMetrics(0)
|
||||
PortableFontInstance::PortableFontInstance(hb_face_t *face, float xScale, float yScale, LEErrorCode &status)
|
||||
: fFace(face), fXScale(xScale), fYScale(yScale), fUnitsPerEM(0), fAscent(0), fDescent(0), fLeading(0),
|
||||
fNAMETable(NULL), fNameCount(0), fNameStringOffset(0), fCMAPMapper(NULL), fHMTXTable(NULL), fNumGlyphs(0), fNumLongHorMetrics(0)
|
||||
{
|
||||
if (LE_FAILURE(status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// open the font file
|
||||
fFile = fopen(fileName, "rb");
|
||||
|
||||
if (fFile == NULL) {
|
||||
status = LE_FONT_FILE_NOT_FOUND_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
// read in the directory
|
||||
SFNTDirectory tempDir;
|
||||
|
||||
fread(&tempDir, sizeof tempDir, 1, fFile);
|
||||
|
||||
le_int32 dirSize = sizeof tempDir + ((SWAPW(tempDir.numTables) - ANY_NUMBER) * sizeof(DirectoryEntry));
|
||||
const LETag headTag = LE_HEAD_TABLE_TAG;
|
||||
const LETag hheaTag = LE_HHEA_TABLE_TAG;
|
||||
const HEADTable *headTable = NULL;
|
||||
const HHEATable *hheaTable = NULL;
|
||||
// const NAMETable *nameTable = NULL;
|
||||
le_uint16 numTables = 0;
|
||||
|
||||
fDirectory = (const SFNTDirectory *) NEW_ARRAY(char, dirSize);
|
||||
|
||||
if (fDirectory == NULL) {
|
||||
status = LE_MEMORY_ALLOCATION_ERROR;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
fseek(fFile, 0L, SEEK_SET);
|
||||
fread((void *) fDirectory, sizeof(char), dirSize, fFile);
|
||||
|
||||
//
|
||||
// We calculate these numbers 'cause some fonts
|
||||
// have bogus values for them in the directory header.
|
||||
//
|
||||
numTables = SWAPW(fDirectory->numTables);
|
||||
fDirPower = 1 << highBit(numTables);
|
||||
fDirExtra = numTables - fDirPower;
|
||||
|
||||
// read unitsPerEm from 'head' table
|
||||
headTable = (const HEADTable *) getFontTable(headTag);
|
||||
|
||||
if (headTable == NULL) {
|
||||
status = LE_MISSING_FONT_TABLE_ERROR;
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
fUnitsPerEM = SWAPW(headTable->unitsPerEm);
|
||||
fFontChecksum = SWAPL(headTable->checksumAdjustment);
|
||||
|
||||
//nameTable = (NAMETable *) getFontTable(nameTag);
|
||||
|
||||
//if (nameTable == NULL) {
|
||||
// status = LE_MISSING_FONT_TABLE_ERROR;
|
||||
// goto error_exit;
|
||||
//}
|
||||
|
||||
//fFontVersionString = findName(nameTable, NAME_VERSION_STRING, PLATFORM_MACINTOSH, MACINTOSH_ROMAN, MACINTOSH_ENGLISH);
|
||||
|
||||
//if (fFontVersionString == NULL) {
|
||||
// status = LE_MISSING_FONT_TABLE_ERROR;
|
||||
// goto error_exit;
|
||||
//}
|
||||
fUnitsPerEM = hb_face_get_upem (face);
|
||||
|
||||
hheaTable = (HHEATable *) getFontTable(hheaTag);
|
||||
|
||||
if (hheaTable == NULL) {
|
||||
status = LE_MISSING_FONT_TABLE_ERROR;
|
||||
goto error_exit;
|
||||
return;
|
||||
}
|
||||
|
||||
fAscent = (le_int32) yUnitsToPoints((float) SWAPW(hheaTable->ascent));
|
||||
|
@ -153,73 +94,14 @@ PortableFontInstance::PortableFontInstance(const char *fileName, float pointSize
|
|||
|
||||
if (fCMAPMapper == NULL) {
|
||||
status = LE_MISSING_FONT_TABLE_ERROR;
|
||||
goto error_exit;
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error_exit:
|
||||
fclose(fFile);
|
||||
fFile = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
PortableFontInstance::~PortableFontInstance()
|
||||
{
|
||||
if (fFile != NULL) {
|
||||
fclose(fFile);
|
||||
|
||||
if (fCMAPMapper)
|
||||
delete fCMAPMapper;
|
||||
|
||||
DELETE_ARRAY(fDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
const DirectoryEntry *PortableFontInstance::findTable(LETag tag) const
|
||||
{
|
||||
if (fDirectory != NULL) {
|
||||
le_uint16 table = 0;
|
||||
le_uint16 probe = fDirPower;
|
||||
|
||||
if (SWAPL(fDirectory->tableDirectory[fDirExtra].tag) <= tag) {
|
||||
table = fDirExtra;
|
||||
}
|
||||
|
||||
while (probe > (1 << 0)) {
|
||||
probe >>= 1;
|
||||
|
||||
if (SWAPL(fDirectory->tableDirectory[table + probe].tag) <= tag) {
|
||||
table += probe;
|
||||
}
|
||||
}
|
||||
|
||||
if (SWAPL(fDirectory->tableDirectory[table].tag) == tag) {
|
||||
return &fDirectory->tableDirectory[table];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const void *PortableFontInstance::readTable(LETag tag, le_uint32 *length) const
|
||||
{
|
||||
const DirectoryEntry *entry = findTable(tag);
|
||||
|
||||
if (entry == NULL) {
|
||||
*length = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*length = SWAPL(entry->length);
|
||||
|
||||
void *table = NEW_ARRAY(char, *length);
|
||||
|
||||
if (table != NULL) {
|
||||
fseek(fFile, SWAPL(entry->offset), SEEK_SET);
|
||||
fread(table, sizeof(char), *length, fFile);
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
const void *PortableFontInstance::getFontTable(LETag tableTag) const
|
||||
|
@ -227,11 +109,9 @@ const void *PortableFontInstance::getFontTable(LETag tableTag) const
|
|||
return FontTableCache::find(tableTag);
|
||||
}
|
||||
|
||||
const void *PortableFontInstance::readFontTable(LETag tableTag) const
|
||||
hb_blob_t *PortableFontInstance::readFontTable(LETag tableTag) const
|
||||
{
|
||||
le_uint32 len;
|
||||
|
||||
return readTable(tableTag, &len);
|
||||
return hb_face_reference_table(fFace, tableTag);
|
||||
}
|
||||
|
||||
CMAPMapper *PortableFontInstance::findUnicodeMapper()
|
||||
|
@ -369,7 +249,7 @@ le_int32 PortableFontInstance::getUnitsPerEM() const
|
|||
|
||||
le_uint32 PortableFontInstance::getFontChecksum() const
|
||||
{
|
||||
return fFontChecksum;
|
||||
return 0;
|
||||
}
|
||||
|
||||
le_int32 PortableFontInstance::getAscent() const
|
||||
|
@ -408,12 +288,12 @@ LEGlyphID PortableFontInstance::mapCharToGlyph(LEUnicode32 ch) const
|
|||
|
||||
float PortableFontInstance::getXPixelsPerEm() const
|
||||
{
|
||||
return fPointSize;
|
||||
return fXScale;
|
||||
}
|
||||
|
||||
float PortableFontInstance::getYPixelsPerEm() const
|
||||
{
|
||||
return fPointSize;
|
||||
return fYScale;
|
||||
}
|
||||
|
||||
float PortableFontInstance::getScaleFactorX() const
|
||||
|
|
|
@ -15,32 +15,29 @@
|
|||
#ifndef __PORTABLEFONTINSTANCE_H
|
||||
#define __PORTABLEFONTINSTANCE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#define HB_H_IN
|
||||
#include <hb-font.h>
|
||||
#include <hb-blob.h>
|
||||
|
||||
#include "layout/LETypes.h"
|
||||
#include "layout/LEFontInstance.h"
|
||||
|
||||
#include "FontTableCache.h"
|
||||
|
||||
#include "sfnt.h"
|
||||
#include "cmaps.h"
|
||||
|
||||
class PortableFontInstance : public LEFontInstance, protected FontTableCache
|
||||
{
|
||||
private:
|
||||
FILE *fFile;
|
||||
hb_face_t *fFace;
|
||||
|
||||
float fPointSize;
|
||||
float fXScale;
|
||||
float fYScale;
|
||||
le_int32 fUnitsPerEM;
|
||||
le_uint32 fFontChecksum;
|
||||
le_int32 fAscent;
|
||||
le_int32 fDescent;
|
||||
le_int32 fLeading;
|
||||
|
||||
const SFNTDirectory *fDirectory;
|
||||
le_uint16 fDirPower;
|
||||
le_uint16 fDirExtra;
|
||||
|
||||
float fDeviceScaleX;
|
||||
float fDeviceScaleY;
|
||||
|
||||
|
@ -56,17 +53,15 @@ private:
|
|||
|
||||
static le_int8 highBit(le_int32 value);
|
||||
|
||||
const DirectoryEntry *findTable(LETag tag) const;
|
||||
const void *readTable(LETag tag, le_uint32 *length) const;
|
||||
void getMetrics();
|
||||
|
||||
CMAPMapper *findUnicodeMapper();
|
||||
|
||||
protected:
|
||||
const void *readFontTable(LETag tableTag) const;
|
||||
hb_blob_t *readFontTable(LETag tableTag) const;
|
||||
|
||||
public:
|
||||
PortableFontInstance(const char *fileName, float pointSize, LEErrorCode &status);
|
||||
PortableFontInstance(hb_face_t *face, float xScale, float yScale, LEErrorCode &status);
|
||||
|
||||
virtual ~PortableFontInstance();
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
This is PortableFontInstance from icu/test/testle of ICU50.
|
||||
Modified to use a hb_face_t.
|
||||
For license information, see the file license.html.
|
||||
|
|
Loading…
Reference in New Issue