FontInstance.cpp revision 73652532c607a400d2e6ee5399154821051e9a3f
/*
* testICU
*
* Authors:
* fred
* bulia byak <buliabyak@users.sf.net>
*
*/
#define PANGO_ENABLE_ENGINE
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ft2build.h>
#include FT_OUTLINE_H
#include FT_BBOX_H
#include FT_TRUETYPE_TAGS_H
#include FT_TRUETYPE_TABLES_H
#include <pango/pangoft2.h>
#include "libnrtype/font-glyph.h"
#include "libnrtype/font-instance.h"
#include "util/unordered-containers.h"
#endif
size_t operator()(font_style const &x) const;
};
bool operator()(font_style const &a, font_style const &b) const;
};
static const double STROKE_WIDTH_THREASHOLD = 0.01;
int h = 0;
h *= 12186;
h += n;
n = (x.vertical) ? 1:0;
h *= 12186;
h += n;
if ( x.stroke_width >= STROKE_WIDTH_THREASHOLD ) {
h *= 12186;
h += n;
if ( x.nbDash > 0 ) {
n = x.nbDash;
h *= 12186;
h += n;
h *= 12186;
h += n;
for (int i = 0; i < x.nbDash; i++) {
h *= 12186;
h += n;
}
}
}
return h;
}
bool same = true;
for (int i = 0; (i < 6) && same; i++) {
}
&& ( a.stroke_join == b.stroke_join )
same = ( static_cast<int>(floor(100 * a.dash_offset)) == static_cast<int>(floor(100 * b.dash_offset)) );
same = ( static_cast<int>(floor(100 * a.dashes[i])) == static_cast<int>(floor(100 * b.dashes[i])) );
}
}
}
return same;
}
#ifndef USE_PANGO_WIN32
/*
* Outline extraction
*/
struct FT2GeomData {
: builder(b)
, last(0, 0)
, scale(s)
{}
double scale;
};
// Note: Freetype 2.2.1 redefined function signatures for functions to be placed in an
// FT_Outline_Funcs structure. This is needed to keep backwards compatibility with the
// 2.1.x series.
/* *** BEGIN #if HACK *** */
typedef FT_Vector const FREETYPE_VECTOR;
#else
typedef FT_Vector FREETYPE_VECTOR;
#endif
// outline as returned by freetype -> livarot Path
// see nr-type-ft2.cpp for the freetype -> artBPath on which this code is based
{
// printf("m t=%f %f\n",p[0],p[1]);
return 0;
}
{
// printf("l t=%f %f\n",p[0],p[1]);
return 0;
}
{
// printf("b c=%f %f t=%f %f\n",c[0],c[1],p[0],p[1]);
return 0;
}
static int ft2_cubic_to(FREETYPE_VECTOR *control1, FREETYPE_VECTOR *control2, FREETYPE_VECTOR *to, void *i_user)
{
// printf("c c1=%f %f c2=%f %f t=%f %f\n",c1[0],c1[1],c2[0],c2[1],p[0],p[1]);
//user->theP->CubicTo(p,3*(c1-user->last),3*(p-c2));
return 0;
}
#endif
/* *** END #if HACK *** */
/*
*
*/
font_instance::font_instance(void) :
pFont(0),
descr(0),
refCount(0),
daddy(0),
nbGlyph(0),
maxGlyph(0),
glyphs(0),
theFace(0)
{
//printf("font instance born\n");
}
font_instance::~font_instance(void)
{
if ( daddy ) {
daddy = 0;
}
//printf("font instance death\n");
if ( pFont ) {
pFont = 0;
}
if ( descr ) {
descr = 0;
}
// if ( theFace ) FT_Done_Face(theFace); // owned by pFont. don't touch
theFace = 0;
for (int i=0;i<nbGlyph;i++) {
if ( glyphs[i].pathvector ) {
delete glyphs[i].pathvector;
}
}
if ( glyphs ) {
glyphs = 0;
}
nbGlyph = 0;
maxGlyph = 0;
}
void font_instance::Ref(void)
{
refCount++;
//char *tc=pango_font_description_to_string(descr);
//printf("font %x %s ref'd %i\n",this,tc,refCount);
//free(tc);
}
void font_instance::Unref(void)
{
refCount--;
//char *tc=pango_font_description_to_string(descr);
//printf("font %x %s unref'd %i\n",this,tc,refCount);
//free(tc);
if ( refCount <= 0 ) {
if ( daddy ) {
}
delete this;
}
}
{
}
{
}
{
}
{
if ( size > 0 ) {
str[0]=0;
}
return 0;
}
bool free_res=false;
free_res=true;
#ifndef USE_PANGO_WIN32
#endif
free_res=false;
bool i = (style == PANGO_STYLE_ITALIC);
bool o = (style == PANGO_STYLE_OBLIQUE);
bool b = (weight >= PANGO_WEIGHT_BOLD);
(b || i || o) ? "-" : "",
(b) ? "Bold" : "",
(i) ? "Italic" : ((o) ? "Oblique" : "") );
free_res = true;
}
free_res=false;
if ( v == PANGO_STYLE_ITALIC ) {
res=(char*)"italic";
} else if ( v == PANGO_STYLE_OBLIQUE ) {
res=(char*)"oblique";
} else {
res=(char*)"normal";
}
free_res=false;
if ( v <= PANGO_WEIGHT_THIN ) {
res=(char*)"100";
} else if ( v <= PANGO_WEIGHT_ULTRALIGHT ) {
res=(char*)"200";
} else if ( v <= PANGO_WEIGHT_LIGHT ) {
res=(char*)"300";
} else if ( v <= PANGO_WEIGHT_BOOK ) {
res=(char*)"380";
} else if ( v <= PANGO_WEIGHT_NORMAL ) {
res=(char*)"normal";
} else if ( v <= PANGO_WEIGHT_MEDIUM ) {
res=(char*)"500";
} else if ( v <= PANGO_WEIGHT_SEMIBOLD ) {
res=(char*)"600";
} else if ( v <= PANGO_WEIGHT_BOLD ) {
res=(char*)"bold";
} else if ( v <= PANGO_WEIGHT_ULTRABOLD ) {
res=(char*)"800";
} else { // HEAVY NB: Pango defines ULTRAHEAVY = 1000 but not CSS2
res=(char*)"900";
}
free_res=false;
if ( v <= PANGO_STRETCH_EXTRA_CONDENSED ) {
res=(char*)"extra-condensed";
} else if ( v <= PANGO_STRETCH_CONDENSED ) {
res=(char*)"condensed";
} else if ( v <= PANGO_STRETCH_SEMI_CONDENSED ) {
res=(char*)"semi-condensed";
} else if ( v <= PANGO_STRETCH_NORMAL ) {
res=(char*)"normal";
} else if ( v <= PANGO_STRETCH_SEMI_EXPANDED ) {
res=(char*)"semi-expanded";
} else if ( v <= PANGO_STRETCH_EXPANDED ) {
res=(char*)"expanded";
} else {
res=(char*)"extra-expanded";
}
free_res=false;
if ( v == PANGO_VARIANT_SMALL_CAPS ) {
res=(char*)"small-caps";
} else {
res=(char*)"normal";
}
free_res=false;
} else {
free_res=false;
}
if ( size > 0 ) {
str[0] = 0;
}
return 0;
}
if (res) {
if ( str ) {
if ( rlen > 0 ) {
}
if ( size > 0 ) {
}
}
if (free_res) {
}
return len;
}
return 0;
}
void font_instance::InitTheFace()
{
#ifdef USE_PANGO_WIN32
if ( !theFace ) {
}
#else
if ( theFace ) {
}
#endif
}
void font_instance::FreeTheFace()
{
#ifdef USE_PANGO_WIN32
#endif
}
{
if ( !iFace ) {
return;
}
InitTheFace();
if ( pFont && IsOutlineFont() == false ) {
FreeTheFace();
if ( pFont ) {
}
}
}
bool font_instance::IsOutlineFont(void)
{
return false;
}
InitTheFace();
#ifdef USE_PANGO_WIN32
#else
return FT_IS_SCALABLE(theFace);
#endif
}
{
int res = 0;
if ( pFont ) {
#ifdef USE_PANGO_WIN32
#else
if ( c > 0xf0000 ) {
} else {
}
#endif
}
return res;
}
#ifdef USE_PANGO_WIN32
{
*(long*)&p.y / 65536.0 * scale);
}
#endif
{
return;
}
InitTheFace();
#ifndef USE_PANGO_WIN32
if ( !FT_IS_SCALABLE(theFace) ) {
return; // bitmap font
}
#endif
}
bool doAdd=false;
#ifdef USE_PANGO_WIN32
#ifndef GGO_UNHINTED // For compatibility with old SDKs.
#define GGO_UNHINTED 0x0100
#endif
DWORD bufferSize=GetGlyphOutline (daddy->hScreenDC, glyph_id, GGO_GLYPH_INDEX | GGO_NATIVE | GGO_UNHINTED, &metrics, 0, NULL, &identity);
if ( bufferSize == GDI_ERROR) {
// shit happened
} else if ( bufferSize == 0) {
// character has no visual representation, but is valid (eg whitespace)
doAdd=true;
} else {
char *buffer = new char[bufferSize];
if ( GetGlyphOutline (daddy->hScreenDC, glyph_id, GGO_GLYPH_INDEX | GGO_NATIVE | GGO_UNHINTED, &metrics, bufferSize, buffer, &identity) <= 0 ) {
// shit happened
} else {
// Platform SDK is rubbish, read KB87115 instead
DWORD polyOffset=0;
while ( polyOffset < bufferSize ) {
case TT_PRIM_LINE:
while ( p != endp )
break;
case TT_PRIM_QSPLINE:
{
// The list of points specifies one or more control points and ends with the end point.
// The intermediate points (on the curve) are the points between the control points.
}
}
break;
case 3: // TT_PRIM_CSPLINE
while ( p != endp ) {
p += 3;
}
break;
}
}
}
}
doAdd=true;
}
delete [] buffer;
}
#else
// shit happened
} else {
if ( FT_HAS_HORIZONTAL(theFace) ) {
} else {
n_g.h_width=n_g.h_advance=((double)(theFace->bbox.xMax-theFace->bbox.xMin))/((double)theFace->units_per_EM);
}
if ( FT_HAS_VERTICAL(theFace) ) {
} else {
}
0, 0
};
}
doAdd=true;
}
#endif
if ( doAdd ) {
// close all paths
i->close();
}
if (bounds) {
}
}
nbGlyph++;
}
} else {
}
}
{
return false;
}
InitTheFace();
return false;
}
#ifdef USE_PANGO_WIN32
return false;
}
//otmSubscriptSize, otmSubscriptOffset, otmSuperscriptSize, otmSuperscriptOffset,
#else
if ( theFace->units_per_EM == 0 ) {
return false; // bitmap font
}
#endif
return true;
}
{
run = 0.0;
rise = 1.0;
return false;
}
InitTheFace();
return false;
}
#ifdef USE_PANGO_WIN32
#else
if ( !FT_IS_SCALABLE(theFace) ) {
return false; // bitmap font
}
return false;
}
#endif
return true;
}
{
int no = -1;
// didn't load
} else {
}
} else {
}
if ( no < 0 ) {
} else {
}
}
{
int no = -1;
// didn't load
} else {
}
} else {
}
}
{
int no = -1;
// didn't load
} else {
}
} else {
}
if ( no >= 0 ) {
if ( vertical ) {
} else {
}
}
return 0;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :