src/gui/text/qfontengine_ft.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    56 
    56 
    57 #include "qfontengine_ft_p.h"
    57 #include "qfontengine_ft_p.h"
    58 #include <ft2build.h>
    58 #include <ft2build.h>
    59 #include FT_FREETYPE_H
    59 #include FT_FREETYPE_H
    60 #include FT_OUTLINE_H
    60 #include FT_OUTLINE_H
       
    61 #include FT_SYNTHESIS_H
    61 #include FT_TRUETYPE_TABLES_H
    62 #include FT_TRUETYPE_TABLES_H
    62 #include FT_TYPE1_TABLES_H
    63 #include FT_TYPE1_TABLES_H
    63 #include FT_GLYPH_H
    64 #include FT_GLYPH_H
    64 
    65 
    65 #if defined(FT_LCD_FILTER_H)
    66 #if defined(FT_LCD_FILTER_H)
   615     matrix.xy = 0;
   616     matrix.xy = 0;
   616     matrix.yx = 0;
   617     matrix.yx = 0;
   617     cache_cost = 100;
   618     cache_cost = 100;
   618     kerning_pairs_loaded = false;
   619     kerning_pairs_loaded = false;
   619     transform = false;
   620     transform = false;
       
   621     embolden = false;
   620     antialias = true;
   622     antialias = true;
   621     freetype = 0;
   623     freetype = 0;
   622     default_load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
   624     default_load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
   623     default_hint_style = HintNone;
   625     default_hint_style = HintNone;
   624     subpixelType = Subpixel_None;
   626     subpixelType = Subpixel_None;
   677     lbearing = rbearing = SHRT_MIN;
   679     lbearing = rbearing = SHRT_MIN;
   678     freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing);
   680     freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing);
   679 
   681 
   680     FT_Face face = lockFace();
   682     FT_Face face = lockFace();
   681 
   683 
   682     //underline metrics
       
   683     if (FT_IS_SCALABLE(face)) {
   684     if (FT_IS_SCALABLE(face)) {
   684         line_thickness =  QFixed::fromFixed(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale));
       
   685         underline_position = QFixed::fromFixed(-FT_MulFix(face->underline_position, face->size->metrics.y_scale));
       
   686         bool fake_oblique = (fontDef.style != QFont::StyleNormal) && !(face->style_flags & FT_STYLE_FLAG_ITALIC);
   685         bool fake_oblique = (fontDef.style != QFont::StyleNormal) && !(face->style_flags & FT_STYLE_FLAG_ITALIC);
   687         if (fake_oblique)
   686         if (fake_oblique)
   688             matrix.xy = 0x10000*3/10;
   687             matrix.xy = 0x10000*3/10;
   689         FT_Set_Transform(face, &matrix, 0);
   688         FT_Set_Transform(face, &matrix, 0);
   690         freetype->matrix = matrix;
   689         freetype->matrix = matrix;
   691         if (fake_oblique)
   690         if (fake_oblique)
   692             transform = true;
   691             transform = true;
       
   692         // fake bold
       
   693         if ((fontDef.weight == QFont::Bold) && !(face->style_flags & FT_STYLE_FLAG_BOLD) && !FT_IS_FIXED_WIDTH(face))
       
   694             embolden = true;
       
   695         // underline metrics
       
   696         line_thickness =  QFixed::fromFixed(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale));
       
   697         underline_position = QFixed::fromFixed(-FT_MulFix(face->underline_position, face->size->metrics.y_scale));
   693     } else {
   698     } else {
   694         // copied from QFontEngineQPF
   699         // copied from QFontEngineQPF
   695         // ad hoc algorithm
   700         // ad hoc algorithm
   696         int score = fontDef.weight * fontDef.pixelSize;
   701         int score = fontDef.weight * fontDef.pixelSize;
   697         line_thickness = score / 700;
   702         line_thickness = score / 700;
   787         g->uploadedToServer = false;
   792         g->uploadedToServer = false;
   788         g->data = 0;
   793         g->data = 0;
   789     }
   794     }
   790 
   795 
   791     FT_GlyphSlot slot = face->glyph;
   796     FT_GlyphSlot slot = face->glyph;
       
   797     if (embolden) FT_GlyphSlot_Embolden(slot);
   792     int left  = slot->metrics.horiBearingX;
   798     int left  = slot->metrics.horiBearingX;
   793     int right = slot->metrics.horiBearingX + slot->metrics.width;
   799     int right = slot->metrics.horiBearingX + slot->metrics.width;
   794     int top    = slot->metrics.horiBearingY;
   800     int top    = slot->metrics.horiBearingY;
   795     int bottom = slot->metrics.horiBearingY - slot->metrics.height;
   801     int bottom = slot->metrics.horiBearingY - slot->metrics.height;
   796     if(transform && slot->format != FT_GLYPH_FORMAT_BITMAP) { // freetype doesn't apply the transformation on the metrics
   802     if(transform && slot->format != FT_GLYPH_FORMAT_BITMAP) { // freetype doesn't apply the transformation on the metrics
   932 
   938 
   933     if (set->outline_drawing && fetchMetricsOnly)
   939     if (set->outline_drawing && fetchMetricsOnly)
   934         return 0;
   940         return 0;
   935 
   941 
   936     FT_GlyphSlot slot = face->glyph;
   942     FT_GlyphSlot slot = face->glyph;
       
   943     if (embolden) FT_GlyphSlot_Embolden(slot);
   937     FT_Library library = qt_getFreetype();
   944     FT_Library library = qt_getFreetype();
   938 
   945 
   939     info.xOff = TRUNC(ROUND(slot->advance.x));
   946     info.xOff = TRUNC(ROUND(slot->advance.x));
   940     info.yOff = 0;
   947     info.yOff = 0;
   941 
   948 
  1207 int QFontEngineFT::synthesized() const
  1214 int QFontEngineFT::synthesized() const
  1208 {
  1215 {
  1209     int s = 0;
  1216     int s = 0;
  1210     if ((fontDef.style != QFont::StyleNormal) && !(freetype->face->style_flags & FT_STYLE_FLAG_ITALIC))
  1217     if ((fontDef.style != QFont::StyleNormal) && !(freetype->face->style_flags & FT_STYLE_FLAG_ITALIC))
  1211         s = SynthesizedItalic;
  1218         s = SynthesizedItalic;
       
  1219     if ((fontDef.weight == QFont::Bold) && !(freetype->face->style_flags & FT_STYLE_FLAG_BOLD))
       
  1220         s |= SynthesizedBold;
  1212     if (fontDef.stretch != 100 && FT_IS_SCALABLE(freetype->face))
  1221     if (fontDef.stretch != 100 && FT_IS_SCALABLE(freetype->face))
  1213         s |= SynthesizedStretch;
  1222         s |= SynthesizedStretch;
  1214     return s;
  1223     return s;
  1215 }
  1224 }
  1216 
  1225