X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flibnrtype%2FFontInstance.cpp;h=e1413b46e788a87f9f90832c551aeec169d4e614;hb=55bd061c7024092e719c231150774b7a1d7c60b9;hp=574a76f628c9f236c7fe0206799207b2988144c3;hpb=762dce10221fb58420527d8554cd5960c03e0eda;p=inkscape.git diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp index 574a76f62..e1413b46e 100644 --- a/src/libnrtype/FontInstance.cpp +++ b/src/libnrtype/FontInstance.cpp @@ -8,13 +8,15 @@ * */ +#define PANGO_ENABLE_ENGINE + #ifdef HAVE_CONFIG_H # include #endif #include #include #include - +#include <2geom/pathvector.h> #include #include "RasterFont.h" @@ -67,7 +69,7 @@ bool font_style_equal::operator()(const font_style &a,const font_style &b) { if ( a.stroke_width > 0.01 && b.stroke_width <= 0.01 ) return false; if ( a.stroke_width <= 0.01 && b.stroke_width > 0.01 ) return false; if ( a.stroke_width <= 0.01 && b.stroke_width <= 0.01 ) return true; - + if ( a.stroke_cap != b.stroke_cap ) return false; if ( a.stroke_join != b.stroke_join ) return false; if ( (int)(a.stroke_miter_limit*100) != (int)(b.stroke_miter_limit*100) ) return false; @@ -87,7 +89,7 @@ bool font_style_equal::operator()(const font_style &a,const font_style &b) { typedef struct ft2_to_liv { Path* theP; double scale; - NR::Point last; + Geom::Point last; } ft2_to_liv; // Note: Freetype 2.2.1 redefined function signatures for functions to be placed in an @@ -105,7 +107,7 @@ typedef FT_Vector FREETYPE_VECTOR; // see nr-type-ft2.cpp for the freetype -> artBPath on which this code is based static int ft2_move_to(FREETYPE_VECTOR *to, void * i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y); + Geom::Point p(user->scale*to->x,user->scale*to->y); // printf("m t=%f %f\n",p[0],p[1]); user->theP->MoveTo(p); user->last=p; @@ -115,7 +117,7 @@ static int ft2_move_to(FREETYPE_VECTOR *to, void * i_user) { static int ft2_line_to(FREETYPE_VECTOR *to, void *i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y); + Geom::Point p(user->scale*to->x,user->scale*to->y); // printf("l t=%f %f\n",p[0],p[1]); user->theP->LineTo(p); user->last=p; @@ -125,7 +127,7 @@ static int ft2_line_to(FREETYPE_VECTOR *to, void *i_user) static int ft2_conic_to(FREETYPE_VECTOR *control, FREETYPE_VECTOR *to, void *i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y),c(user->scale*control->x,user->scale*control->y); + 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]); user->theP->BezierTo(p); user->theP->IntermBezierTo(c); @@ -137,11 +139,11 @@ static int ft2_conic_to(FREETYPE_VECTOR *control, FREETYPE_VECTOR *to, void *i_u static int ft2_cubic_to(FREETYPE_VECTOR *control1, FREETYPE_VECTOR *control2, FREETYPE_VECTOR *to, void *i_user) { ft2_to_liv* user=(ft2_to_liv*)i_user; - NR::Point p(user->scale*to->x,user->scale*to->y), + Geom::Point p(user->scale*to->x,user->scale*to->y), c1(user->scale*control1->x,user->scale*control1->y), - c2(user->scale*control2->x,user->scale*control2->y); + c2(user->scale*control2->x,user->scale*control2->y); // 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)); + user->theP->CubicTo(p,3*(c1-user->last),3*(p-c2)); user->last=p; return 0; } @@ -178,7 +180,7 @@ font_instance::~font_instance(void) for (int i=0;i= PANGO_WEIGHT_BOLD); - - res = g_strdup_printf ("%s%s%s%s", - pango_font_description_get_family(descr), - (b || i || o) ? "-" : "", - (b) ? "Bold" : "", + + res = g_strdup_printf ("%s%s%s%s", + pango_font_description_get_family(descr), + (b || i || o) ? "-" : "", + (b) ? "Bold" : "", (i) ? "Italic" : ((o) ? "Oblique" : "") ); free_res = true; } @@ -261,51 +263,53 @@ unsigned int font_instance::Attribute(const gchar *key, gchar *str, unsigned int } else if ( strcmp(key,"style") == 0 ) { PangoStyle v=pango_font_description_get_style(descr); if ( v == PANGO_STYLE_ITALIC ) { - res="italic"; + res=(char*)"italic"; } else if ( v == PANGO_STYLE_OBLIQUE ) { - res="oblique"; + res=(char*)"oblique"; } else { - res="normal"; + res=(char*)"normal"; } free_res=false; } else if ( strcmp(key,"weight") == 0 ) { PangoWeight v=pango_font_description_get_weight(descr); if ( v <= PANGO_WEIGHT_ULTRALIGHT ) { - res="200"; + res=(char*)"200"; } else if ( v <= PANGO_WEIGHT_LIGHT ) { - res="300"; + res=(char*)"300"; } else if ( v <= PANGO_WEIGHT_NORMAL ) { - res="normal"; + res=(char*)"normal"; } else if ( v <= PANGO_WEIGHT_BOLD ) { - res="bold"; - } else { - res="800"; + res=(char*)"bold"; + } else if ( v <= PANGO_WEIGHT_ULTRABOLD ) { + res=(char*)"800"; + } else { // HEAVY + res=(char*)"900"; } free_res=false; } else if ( strcmp(key,"stretch") == 0 ) { PangoStretch v=pango_font_description_get_stretch(descr); if ( v <= PANGO_STRETCH_EXTRA_CONDENSED ) { - res="extra-condensed"; + res=(char*)"extra-condensed"; } else if ( v <= PANGO_STRETCH_CONDENSED ) { - res="condensed"; + res=(char*)"condensed"; } else if ( v <= PANGO_STRETCH_SEMI_CONDENSED ) { - res="semi-condensed"; + res=(char*)"semi-condensed"; } else if ( v <= PANGO_STRETCH_NORMAL ) { - res="normal"; + res=(char*)"normal"; } else if ( v <= PANGO_STRETCH_SEMI_EXPANDED ) { - res="semi-expanded"; + res=(char*)"semi-expanded"; } else if ( v <= PANGO_STRETCH_EXPANDED ) { - res="expanded"; + res=(char*)"expanded"; } else { - res="extra-expanded"; + res=(char*)"extra-expanded"; } free_res=false; } else if ( strcmp(key,"variant") == 0 ) { PangoVariant v=pango_font_description_get_variant(descr); if ( v == PANGO_VARIANT_SMALL_CAPS ) { - res="small-caps"; + res=(char*)"small-caps"; } else { - res="normal"; + res=(char*)"normal"; } free_res=false; } else { @@ -316,7 +320,7 @@ unsigned int font_instance::Attribute(const gchar *key, gchar *str, unsigned int if ( size > 0 ) str[0]=0; return 0; } - + if (res) { unsigned int len=strlen(res); unsigned int rlen=(size-1cpfx >= 2); endp -= 2; - NR::Point this_mid=pointfx_to_nrpoint(p[0], scale); + Geom::Point this_mid=pointfx_to_nrpoint(p[0], scale); while ( p != endp ) { - NR::Point next_mid=pointfx_to_nrpoint(p[1], scale); + Geom::Point next_mid=pointfx_to_nrpoint(p[1], scale); n_g.outline->BezierTo((next_mid+this_mid)/2); n_g.outline->IntermBezierTo(this_mid); n_g.outline->EndBezierTo(); @@ -544,7 +548,7 @@ void font_instance::LoadGlyph(int glyph_id) ft2_to_liv tData; tData.theP=n_g.outline; tData.scale=1.0/((double)theFace->units_per_EM); - tData.last=NR::Point(0,0); + tData.last=Geom::Point(0,0); FT_Outline_Decompose (&theFace->glyph->outline, &ft2_outline_funcs, &tData); } doAdd=true; @@ -554,7 +558,7 @@ void font_instance::LoadGlyph(int glyph_id) if ( doAdd ) { if ( n_g.outline ) { n_g.outline->FastBBox(n_g.bbox[0],n_g.bbox[1],n_g.bbox[2],n_g.bbox[3]); - n_g.artbpath=n_g.outline->MakeArtBPath(); + n_g.pathvector=n_g.outline->MakePathVector(); } glyphs[nbGlyph]=n_g; id_to_no[glyph_id]=nbGlyph; @@ -602,7 +606,7 @@ bool font_instance::FontSlope(double &run, double &rise) rise=otm.otmsCharSlopeRise; #else if ( !FT_IS_SCALABLE(theFace) ) return false; // bitmap font - + TT_HoriHeader *hhea = (TT_HoriHeader*)FT_Get_Sfnt_Table(theFace, ft_sfnt_hhea); if (hhea == NULL) return false; run = hhea->caret_Slope_Run; @@ -611,7 +615,7 @@ bool font_instance::FontSlope(double &run, double &rise) return true; } -NR::Rect font_instance::BBox(int glyph_id) +Geom::OptRect font_instance::BBox(int glyph_id) { int no=-1; if ( id_to_no.find(glyph_id) == id_to_no.end() ) { @@ -624,11 +628,13 @@ NR::Rect font_instance::BBox(int glyph_id) } else { no=id_to_no[glyph_id]; } - if ( no < 0 ) return NR::Rect(NR::Point(0,0),NR::Point(0,0)); - NR::Point rmin(glyphs[no].bbox[0],glyphs[no].bbox[1]); - NR::Point rmax(glyphs[no].bbox[2],glyphs[no].bbox[3]); - NR::Rect res(rmin,rmax); - return res; + if ( no < 0 ) { + return Geom::OptRect(); + } else { + Geom::Point rmin(glyphs[no].bbox[0],glyphs[no].bbox[1]); + Geom::Point rmax(glyphs[no].bbox[2],glyphs[no].bbox[3]); + return Geom::Rect(rmin, rmax); + } } Path* font_instance::Outline(int glyph_id,Path* copyInto) @@ -654,21 +660,21 @@ Path* font_instance::Outline(int glyph_id,Path* copyInto) return src_o; } -void* font_instance::ArtBPath(int glyph_id) +Geom::PathVector* font_instance::PathVector(int glyph_id) { - int no=-1; - if ( id_to_no.find(glyph_id) == id_to_no.end() ) { - LoadGlyph(glyph_id); - if ( id_to_no.find(glyph_id) == id_to_no.end() ) { - // didn't load - } else { - no=id_to_no[glyph_id]; - } - } else { - no=id_to_no[glyph_id]; - } - if ( no < 0 ) return NULL; - return glyphs[no].artbpath; + int no = -1; + if ( id_to_no.find(glyph_id) == id_to_no.end() ) { + LoadGlyph(glyph_id); + if ( id_to_no.find(glyph_id) == id_to_no.end() ) { + // didn't load + } else { + no = id_to_no[glyph_id]; + } + } else { + no = id_to_no[glyph_id]; + } + if ( no < 0 ) return NULL; + return glyphs[no].pathvector; } double font_instance::Advance(int glyph_id,bool vertical) @@ -692,10 +698,10 @@ double font_instance::Advance(int glyph_id,bool vertical) } } return 0; -} +} -raster_font* font_instance::RasterFont(const NR::Matrix &trs,double stroke_width,bool vertical,JoinType stroke_join,ButtType stroke_cap,float miter_limit) +raster_font* font_instance::RasterFont(const Geom::Matrix &trs, double stroke_width, bool vertical, JoinType stroke_join, ButtType stroke_cap, float /*miter_limit*/) { font_style nStyle; nStyle.transform=trs;