text_view.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef TEXT_VIEW_H
00028 #define TEXT_VIEW_H
00029
00030 #include <string>
00031 #include <pango/pango.h>
00032 #include <pango/pangoft2.h>
00033
00034 #include <ft2build.h>
00035 #include FT_FREETYPE_H
00036 #include FT_GLYPH_H
00037
00038 #include "plugin_render_result.h"
00039
00040 #include "thread.h"
00041 #include "signal_slot.h"
00042 #include "text_base_types.h"
00043 #include "text_model.h"
00044 #include "text_controller.h"
00045
00046 namespace text
00047 {
00048
00049 class PaginationTask;
00050
00051 class TextView
00052 {
00053 public:
00054
00055 TextView(TextModel *m);
00056 ~TextView();
00057
00058 public:
00059
00060 void initialize();
00061
00062
00063 void deinitialize();
00064
00065 void set_controller(TextController* c)
00066 {
00067 ctrl = c;
00068 }
00069
00070 TextController* get_controller()
00071 {
00072 return ctrl;
00073 }
00074
00075
00076
00077
00078
00079 bool paginate(const Position& start_pos);
00080
00081
00082 void clear_pages()
00083 {
00084 pages.clear();
00085 }
00086
00087
00088
00089 Position render(unsigned char *bmp, const Position& start_pos);
00090
00091 const TextModel* get_model() const
00092 {
00093 return model;
00094 }
00095
00096
00097 int get_font_size() const
00098 {
00099 return font_size;
00100 }
00101
00102
00103 bool set_font_size(int font_size);
00104
00105
00106 const std::string& get_font_family() const
00107 {
00108 return font_family;
00109 }
00110
00111
00112 void set_font_family(const std::string& font_family)
00113 {
00114 this->font_family = font_family;
00115 }
00116
00117
00118 void get_display_size(int& width, int& height)
00119 {
00120 width = display_width;
00121 height = display_height;
00122 }
00123
00124
00125 void set_display_size(unsigned int width, unsigned int height);
00126
00127
00128 unsigned int get_DPI()
00129 {
00130 return dpi;
00131 }
00132
00133
00134 void set_DPI(unsigned int dpi)
00135 {
00136 this->dpi = dpi;
00137 }
00138
00139
00140 unsigned int get_color_depth()
00141 {
00142 return color_depth;
00143 }
00144
00145
00146 void set_color_depth(unsigned int color_depth)
00147 {
00148 this->color_depth = color_depth;
00149 }
00150
00151 int get_page_count()
00152 {
00153 if (!pages.empty() && pages.back().end == Position(0, 0))
00154 {
00155 return static_cast<int>(pages.size());
00156 }
00157 return 0;
00158 }
00159
00160
00161 void check_page_table(const Position& rendering_pos);
00162
00163
00164 bool get_anchor_by_page(unsigned int page_index, Position& pos);
00165
00166
00167
00168
00169 unsigned int get_page_index_by_anchor(const Position& anchor);
00170
00171
00172 Position get_page_anchor_by_anchor(const Position& anchor);
00173
00174
00175
00176
00177 unsigned int get_current_page_index();
00178
00179
00180
00181
00182
00183
00184 bool map_doc_pos_to_view_pos(const Position& page_anchor,
00185 const Position& doc_pos,
00186 ViewPosition& view_pos,
00187 bool trailing);
00188
00189
00190
00191
00192
00193
00194 bool map_view_pos_to_doc_pos(const Position& page_anchor,
00195 const ViewPosition& view_pos,
00196 Position& doc_pos);
00197
00198
00199 bool get_bounding_rectangles(const Position& page_anchor,
00200 std::vector<Rect>& bounding_rect,
00201 const Range& range);
00202
00203
00204
00205
00206
00207 bool calculate_next_page_pos(const Position& in_pos, Position& out_pos);
00208
00209
00210
00211
00212
00213 bool calculate_prev_page_pos(const Position& in_pos, Position& out_pos);
00214
00215
00216 bool need_repagination()
00217 {
00218 return is_repagination_needed;
00219 }
00220
00221 public:
00222
00223 utils::Signal<unsigned int> pagination_start_signal;
00224 utils::Signal<unsigned int, unsigned int> pagination_end_signal;
00225 utils::Signal<unsigned int,
00226 const Position&,
00227 const Position&,
00228 void *> render_done_signal;
00229
00230 private:
00231
00232 void pango_context_init();
00233
00234
00235 void pango_context_final();
00236
00237
00238 void calculate_lines_per_page();
00239
00240
00241
00242 PangoLayout* create_layout(const char *str, int len);
00243
00244 private:
00245
00246 TextModel *model;
00247
00248
00249 TextController *ctrl;
00250
00251
00252 std::string font_family;
00253
00254
00255 int font_size;
00256
00257
00258 unsigned int display_width;
00259
00260
00261 unsigned int display_height;
00262
00263
00264 unsigned int dpi;
00265
00266
00267 unsigned int color_depth;
00268
00269
00270 unsigned int line_height;
00271
00272
00273 unsigned int lines_per_page;
00274
00275
00276 unsigned int left_margin;
00277
00278
00279 unsigned int right_margin;
00280
00281
00282 unsigned int top_margin;
00283
00284
00285 unsigned int bottom_margin;
00286
00287
00288 unsigned int client_width;
00289
00290
00291 unsigned int client_height;
00292
00293
00294 Position rendering_pos;
00295
00296
00297 typedef SafeDeque<PageInfo> PageTable;
00298 PageTable pages;
00299
00300
00301 PangoContext *pango_context;
00302
00303
00304 GMutex *pango_mutex;
00305 unsigned int font_hash_code;
00306
00307
00308 bool is_repagination_needed;
00309
00310
00311 unsigned int blank_lines;
00312 };
00313
00314 };
00315
00316 #endif // TEXT_VIEW_H
00317
00318