FontInstance.cpp revision 8d590f3f898ef98b32edae640e2bf6c3cf745c41
/*
* testICU
*
* Authors:
* fred
* bulia byak <buliabyak@users.sf.net>
*
*/
#define PANGO_ENABLE_ENGINE
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <libnrtype/font-glyph.h>
#include <libnrtype/font-instance.h>
#include "RasterFont.h"
/* Freetype 2 */
# 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>
// the various raster_font in use at a given time are held in a hash_map whose indices are the
// styles, hence the 2 following 'classes'
size_t operator()(font_style const &x) const;
};
bool operator()(font_style const &a, font_style const &b);
};
int h=0,n;
h*=12186;
h+=n;
n=(x.vertical)?1:0;
h*=12186;
h+=n;
if ( x.stroke_width >= 0.01 ) {
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;
}
for (int i=0;i<6;i++) {
}
if ( a.stroke_cap != b.stroke_cap ) return false;
if ( a.stroke_join != b.stroke_join ) return false;
if ( a.nbDash <= 0 ) return true;
for (int i=0;i<a.nbDash;i++) {
}
return true;
}
#ifndef USE_PANGO_WIN32
/*
* Outline extraction
*/
typedef struct ft2_to_liv {
double scale;
} ft2_to_liv;
// 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;
}
{
Geom::Point p(user->scale*to->x,user->scale*to->y),c(user->scale*control->x,user->scale*control->y);
// 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]);
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 ( loadedPtr ) {
delete tmp;
loadedPtr = 0;
}
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 ) {
delete this;
}
}
{
}
{
}
{
}
{
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_ULTRALIGHT ) {
res=(char*)"200";
} else if ( v <= PANGO_WEIGHT_LIGHT ) {
res=(char*)"300";
} else if ( v <= PANGO_WEIGHT_NORMAL ) {
res=(char*)"normal";
} else if ( v <= PANGO_WEIGHT_BOLD ) {
res=(char*)"bold";
} else if ( v <= PANGO_WEIGHT_ULTRABOLD ) {
res=(char*)"800";
} else { // HEAVY
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;
}
return 0;
}
if (res) {
if ( str ) {
}
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();
}
}
bool font_instance::IsOutlineFont(void)
{
InitTheFace();
#ifdef USE_PANGO_WIN32
#else
return FT_IS_SCALABLE(theFace);
#endif
}
{
#ifdef USE_PANGO_WIN32
return pango_win32_font_get_glyph_index(pFont,c);
#else
int res=0;
if ( c > 0xf0000 ) {
} else {
}
return res;
#endif
}
#ifdef USE_PANGO_WIN32
{
*(long*)&p.y / 65536.0 * scale);
}
#endif
{
InitTheFace();
#ifndef USE_PANGO_WIN32
#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 {
if ( GetGlyphOutline (daddy->hScreenDC, glyph_id, GGO_GLYPH_INDEX | GGO_NATIVE | GGO_UNHINTED, &metrics, bufferSize, buffer.get(), &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:
{
endp -= 2;
while ( p != endp ) {
++p;
}
break;
}
case 3: // TT_PRIM_CSPLINE
while ( p != endp ) {
n_g.outline->CubicTo(pointfx_to_nrpoint(p[2], scale), pointfx_to_nrpoint(p[0], scale), pointfx_to_nrpoint(p[1], scale));
p += 3;
}
break;
}
}
}
}
doAdd=true;
}
}
#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 ) {
}
nbGlyph++;
}
} else {
}
}
{
InitTheFace();
#ifdef USE_PANGO_WIN32
#else
#endif
return true;
}
{
run = 0.0;
rise = 1.0;
InitTheFace();
#ifdef USE_PANGO_WIN32
#else
#endif
return true;
}
{
int no=-1;
// didn't load
} else {
}
} else {
}
if ( no < 0 ) {
} else {
}
}
{
int no=-1;
// didn't load
} else {
}
} else {
}
if ( copyInto ) {
return copyInto;
}
return src_o;
}
{
int no = -1;
// didn't load
} else {
}
} else {
}
}
{
int no=-1;
// didn't load
} else {
}
} else {
}
if ( no >= 0 ) {
if ( vertical ) {
} else {
}
}
return 0;
}
raster_font* font_instance::RasterFont(const Geom::Matrix &trs, double stroke_width, bool vertical, JoinType stroke_join, ButtType stroke_cap, float /*miter_limit*/)
{
return RasterFont(nStyle);
}
{
// for some evil reason font_style doesn't have a copy ctor, so the
// stuff that should be done there is done here instead (because the
// raster_font ctor copies nStyle).
}
} else {
}
return res;
}
{
if ( who ) {
//g_print("RemoveRasterFont failed \n");
// not found
} else {
//g_print("RemoveRasterFont\n");
Unref();
}
}
}
/*
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 :