Implement image handling
[claws.git] / src / plugins / litehtml_viewer / container_linux.h
1 #pragma once
2
3 #include <vector>
4 #include <string>
5
6 #include <cairo.h>
7 #include <gtk/gtk.h>
8 #include <fontconfig/fontconfig.h>
9
10 #include "litehtml/litehtml.h"
11
12 struct cairo_clip_box
13 {
14         typedef std::vector<cairo_clip_box> vector;
15         litehtml::position      box;
16         litehtml::border_radiuses radius;
17
18         cairo_clip_box(const litehtml::position& vBox, litehtml::border_radiuses vRad)
19         {
20                 box = vBox;
21                 radius = vRad;
22         }
23
24         cairo_clip_box(const cairo_clip_box& val)
25         {
26                 box = val.box;
27                 radius = val.radius;
28         }
29         cairo_clip_box& operator=(const cairo_clip_box& val)
30         {
31                 box = val.box;
32                 radius = val.radius;
33                 return *this;
34         }
35 };
36
37 struct cairo_font
38 {
39         cairo_font_face_t*      font;
40         int                                     size;
41         bool                            underline;
42         bool                            strikeout;
43 };
44
45 class container_linux : public litehtml::document_container
46 {
47         typedef std::map<litehtml::tstring, GdkPixbuf* >        images_map;
48
49 protected:
50         cairo_surface_t*                        m_temp_surface;
51         cairo_t*                                        m_temp_cr;
52         images_map                                      m_images;
53     cairo_clip_box::vector              m_clips;
54 public:
55         container_linux(void);
56         virtual ~container_linux(void);
57
58         virtual litehtml::uint_ptr                      create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
59         virtual void                                            delete_font(litehtml::uint_ptr hFont) override;
60         virtual int                                             text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
61         virtual void                                            draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
62         virtual int                                             pt_to_px(int pt) override;
63         virtual int                                             get_default_font_size() const override;
64         virtual const litehtml::tchar_t*        get_default_font_name() const override;
65         virtual void                                            load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
66         virtual void                                            get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
67         virtual void                                            draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
68         virtual void                                            draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
69         virtual void                                            draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
70         virtual std::shared_ptr<litehtml::element>      create_element(const litehtml::tchar_t *tag_name,
71                                                                                                                                  const litehtml::string_map &attributes,
72                                                                                                                                  const std::shared_ptr<litehtml::document> &doc) override;
73         virtual void                                            get_media_features(litehtml::media_features& media) const override;
74         virtual void                                            get_language(litehtml::tstring& language, litehtml::tstring & culture) const override;
75         virtual void                                            link(const std::shared_ptr<litehtml::document> &ptr, const litehtml::element::ptr& el) override;
76
77
78         virtual void                                            transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
79         virtual void                                            set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
80         virtual void                                            del_clip() override;
81
82         virtual void                                            make_url( const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out );
83         virtual GdkPixbuf       *get_image(const litehtml::tchar_t* url, bool redraw_on_ready) = 0;
84
85         void                                                            clear_images();
86
87 protected:
88         virtual void                                            draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
89         virtual void                                            fill_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color);
90         virtual void                                            rounded_rectangle( cairo_t* cr, const litehtml::position &pos, const litehtml::border_radiuses &radius );
91
92 private:
93         void                                                            apply_clip(cairo_t* cr);
94         void                                                            add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg);
95         void                                                            set_color(cairo_t* cr, litehtml::web_color color)       { cairo_set_source_rgba(cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0, color.alpha / 255.0); }
96         void                                                            draw_pixbuf(cairo_t* cr, const GdkPixbuf *bmp, int x, int y, int cx, int cy);
97         cairo_surface_t*                                        surface_from_pixbuf(const GdkPixbuf *bmp);
98 };