view-cairo.hh revision 078de49ca10285f6cd1452abd40f831a17af5d1a
1/* 2 * Copyright © 2011 Google, Inc. 3 * 4 * This is part of HarfBuzz, a text shaping library. 5 * 6 * Permission is hereby granted, without written agreement and without 7 * license or royalty fees, to use, copy, modify, and distribute this 8 * software and its documentation for any purpose, provided that the 9 * above copyright notice and the following two paragraphs appear in 10 * all copies of this software. 11 * 12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 16 * DAMAGE. 17 * 18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 23 * 24 * Google Author(s): Behdad Esfahbod 25 */ 26 27#include "options.hh" 28#include "helper-cairo.hh" 29 30#ifndef VIEW_CAIRO_HH 31#define VIEW_CAIRO_HH 32 33 34struct view_cairo_t 35{ 36 view_cairo_t (option_parser_t *parser) 37 : output_options (parser, helper_cairo_supported_formats), 38 view_options (parser), 39 lines (0), scale (1.0) {} 40 ~view_cairo_t (void) { 41 if (debug) 42 cairo_debug_reset_static_data (); 43 } 44 45 void init (const font_options_t *font_opts) 46 { 47 lines = g_array_new (false, false, sizeof (helper_cairo_line_t)); 48 scale = double (view_options.font_size) / hb_face_get_upem (hb_font_get_face (font_opts->get_font ())); 49 } 50 void new_line (void) 51 { 52 } 53 void consume_text (hb_buffer_t *buffer, 54 const char *text, 55 unsigned int text_len, 56 hb_bool_t utf8_clusters) 57 { 58 } 59 void shape_failed (hb_buffer_t *buffer, 60 const char *text, 61 unsigned int text_len, 62 hb_bool_t utf8_clusters) 63 { 64 fail (false, "all shapers failed"); 65 } 66 void consume_glyphs (hb_buffer_t *buffer, 67 const char *text, 68 unsigned int text_len, 69 hb_bool_t utf8_clusters) 70 { 71 direction = hb_buffer_get_direction (buffer); 72 helper_cairo_line_t l; 73 helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale, utf8_clusters); 74 g_array_append_val (lines, l); 75 } 76 void finish (const font_options_t *font_opts) 77 { 78 render (font_opts); 79 80 for (unsigned int i = 0; i < lines->len; i++) { 81 helper_cairo_line_t &line = g_array_index (lines, helper_cairo_line_t, i); 82 line.finish (); 83 } 84 g_array_free (lines, TRUE); 85 } 86 87 protected: 88 89 output_options_t output_options; 90 view_options_t view_options; 91 92 void render (const font_options_t *font_opts); 93 void get_surface_size (cairo_scaled_font_t *scaled_font, double *w, double *h); 94 void draw (cairo_t *cr); 95 96 hb_direction_t direction; // Remove this, make segment_properties accessible 97 GArray *lines; 98 double scale; 99}; 100 101#endif 102