Use Pango to render text in Litehtml plugin
[claws.git] / src / plugins / litehtml_viewer / container_linux.cpp
index e4d3c1dad93092d393d578641b18650c803efcd3..15f8836ad3be5aa77387131077e5afa9116f8eb6 100644 (file)
@@ -46,169 +46,6 @@ container_linux::~container_linux(void)
        cairo_destroy(m_temp_cr);
 }
 
-litehtml::uint_ptr container_linux::create_font( const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm )
-{
-       litehtml::string_vector fonts;
-       litehtml::split_string(faceName, fonts, ",");
-       if (! fonts.empty()) {
-           litehtml::trim(fonts[0]);
-       }
-
-       cairo_font_face_t* fnt = 0;
-
-       FcPattern *pattern = FcPatternCreate();
-       bool found = false;
-       for(litehtml::string_vector::iterator i = fonts.begin(); i != fonts.end(); i++)
-       {
-               if(FcPatternAddString(pattern, FC_FAMILY, (unsigned char *) i->c_str()))
-               {
-                       found = true;
-                       break;
-               }
-       }
-       if(found)
-       {
-               if(italic == litehtml::fontStyleItalic )
-               {
-                       FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ITALIC);
-               } else
-               {
-                       FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN);
-               }
-
-               int fc_weight = FC_WEIGHT_NORMAL;
-               if(weight >= 0 && weight < 150)                 fc_weight = FC_WEIGHT_THIN;
-               else if(weight >= 150 && weight < 250)  fc_weight = FC_WEIGHT_EXTRALIGHT;
-               else if(weight >= 250 && weight < 350)  fc_weight = FC_WEIGHT_LIGHT;
-               else if(weight >= 350 && weight < 450)  fc_weight = FC_WEIGHT_NORMAL;
-               else if(weight >= 450 && weight < 550)  fc_weight = FC_WEIGHT_MEDIUM;
-               else if(weight >= 550 && weight < 650)  fc_weight = FC_WEIGHT_SEMIBOLD;
-               else if(weight >= 650 && weight < 750)  fc_weight = FC_WEIGHT_BOLD;
-               else if(weight >= 750 && weight < 850)  fc_weight = FC_WEIGHT_EXTRABOLD;
-               else if(weight >= 950)                                  fc_weight = FC_WEIGHT_BLACK;
-
-               FcPatternAddInteger (pattern, FC_WEIGHT, fc_weight);
-
-               fnt = cairo_ft_font_face_create_for_pattern(pattern);
-       }
-
-       FcPatternDestroy(pattern);
-
-       cairo_font* ret = 0;
-
-       if(fm && fnt)
-       {
-               cairo_save(m_temp_cr);
-
-               cairo_set_font_face(m_temp_cr, fnt);
-               cairo_set_font_size(m_temp_cr, size);
-               cairo_font_extents_t ext;
-               cairo_font_extents(m_temp_cr, &ext);
-
-               cairo_text_extents_t tex;
-               cairo_text_extents(m_temp_cr, "x", &tex);
-
-               fm->ascent              = (int) ext.ascent;
-               fm->descent             = (int) ext.descent;
-               fm->height              = (int) (ext.ascent + ext.descent);
-               fm->x_height    = (int) tex.height;
-
-               cairo_restore(m_temp_cr);
-
-               ret = new cairo_font;
-               ret->font               = fnt;
-               ret->size               = size;
-               ret->strikeout  = (decoration & litehtml::font_decoration_linethrough) ? true : false;
-               ret->underline  = (decoration & litehtml::font_decoration_underline) ? true : false;
-
-       }
-
-       return (litehtml::uint_ptr) ret;
-}
-
-void container_linux::delete_font( litehtml::uint_ptr hFont )
-{
-       cairo_font* fnt = (cairo_font*) hFont;
-       if(fnt)
-       {
-               cairo_font_face_destroy(fnt->font);
-               delete fnt;
-       }
-}
-
-int container_linux::text_width( const litehtml::tchar_t* text, litehtml::uint_ptr hFont )
-{
-       cairo_font* fnt = (cairo_font*) hFont;
-
-       cairo_save(m_temp_cr);
-
-       if (fnt) {
-           cairo_set_font_size(m_temp_cr, fnt->size);
-           cairo_set_font_face(m_temp_cr, fnt->font);
-       }
-       cairo_text_extents_t ext;
-       cairo_text_extents(m_temp_cr, text, &ext);
-
-       cairo_restore(m_temp_cr);
-
-       return (int) ext.x_advance;
-}
-
-void container_linux::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos )
-{
-       cairo_font* fnt = (cairo_font*) hFont;
-       cairo_t* cr             = (cairo_t*) hdc;
-       cairo_save(cr);
-
-       apply_clip(cr);
-
-       if (fnt) {
-           cairo_set_font_face(cr, fnt->font);
-           cairo_set_font_size(cr, fnt->size);
-       }
-       cairo_font_extents_t ext;
-       cairo_font_extents(cr, &ext);
-
-       int x = pos.left();
-       int y = pos.bottom()    - ext.descent;
-
-       set_color(cr, color);
-
-       cairo_move_to(cr, x, y);
-       cairo_show_text(cr, text);
-
-       int tw = 0;
-
-       if (fnt) {
-           if(fnt->underline || fnt->strikeout)
-           {
-               tw = text_width(text, hFont);
-           }
-
-           if(fnt->underline)
-           {
-               cairo_set_line_width(cr, 1);
-               cairo_move_to(cr, x, y + 1.5);
-               cairo_line_to(cr, x + tw, y + 1.5);
-               cairo_stroke(cr);
-           }
-           if(fnt->strikeout)
-           {
-               cairo_text_extents_t tex;
-               cairo_text_extents(cr, "x", &tex);
-
-               int ln_y = y - tex.height / 2.0;
-
-               cairo_set_line_width(cr, 1);
-               cairo_move_to(cr, x, (double) ln_y - 0.5);
-               cairo_line_to(cr, x + tw, (double) ln_y - 0.5);
-               cairo_stroke(cr);
-           }
-       }   
-
-       cairo_restore(cr);
-}
-
 int container_linux::pt_to_px( int pt )
 {
        GdkScreen* screen = gdk_screen_get_default();
@@ -217,11 +54,6 @@ int container_linux::pt_to_px( int pt )
        return (int) ((double) pt * dpi / 72.0);
 }
 
-int container_linux::get_default_font_size() const
-{
-       return 16;
-}
-
 void container_linux::draw_list_marker( litehtml::uint_ptr hdc, const litehtml::list_marker& marker )
 {
        if(!marker.image.empty())
@@ -834,9 +666,10 @@ void container_linux::clear_images()
        m_images.clear();
 }
 
-void container_linux::clear_images(gint desired_size)
+gint container_linux::clear_images(gint desired_size)
 {
        gint size = 0;
+       gint num = 0;
 
        /* First, tally up size of all the stored GdkPixbufs and
         * deallocate those which make the total size be above
@@ -854,6 +687,7 @@ void container_linux::clear_images(gint desired_size)
                if (size + cursize > desired_size) {
                        g_object_unref(img->second);
                        img->second = NULL;
+                       num++;
                } else {
                        size += cursize;
                }
@@ -865,11 +699,8 @@ void container_linux::clear_images(gint desired_size)
                                return true;
                        return false;
                        });
-}
 
-const litehtml::tchar_t* container_linux::get_default_font_name() const
-{
-       return "Times New Roman";
+       return num;
 }
 
 std::shared_ptr<litehtml::element>     container_linux::create_element(const litehtml::tchar_t *tag_name,