Mercurial > hg > octave-lyh
diff src/txt-eng-ft.cc @ 12965:22bc9ec80c2c
allow multi-line string property for text objects using cell arrays or char matrices
* __axis_label__.m: Don't check type of txt argument.
* __go_draw_axes__.m: Handle multi-line string property for
text objects.
* text.m: Likewise.
* gl2ps-renderer.cc (glps_renderer::draw_text): Handle
text::properties string property as octave_value object that can
contain either a char array or cellstr object.
* graphics.cc (axes::properties::update_xlabel_position,
axes::properties::update_ylabel_position,
axes::properties::update_zlabel_position,
axes::properties::get_extent, text::properties::update_text_extent): Likewise.
* graphics.h.in (text_label_property::do_set): Don't forget to set
stored_type when value is a cell.
(text::properties::get_string): Delete custom getter.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Mon, 15 Aug 2011 10:24:09 -0400 |
parents | 63dc132a1000 |
children | 6fc2c61660f2 |
line wrap: on
line diff
--- a/src/txt-eng-ft.cc +++ b/src/txt-eng-ft.cc @@ -270,6 +270,7 @@ { if (face) { + FT_UInt box_line_width = 0; std::string str = e.string_value (); FT_UInt glyph_index, previous = 0; @@ -277,8 +278,9 @@ { glyph_index = FT_Get_Char_Index (face, str[i]); - if (! glyph_index - || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) + if (str[i] != '\n' + && (! glyph_index + || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT))) ::warning ("ft_render: skipping missing glyph for character `%c'", str[i]); else @@ -286,7 +288,20 @@ switch (mode) { case MODE_RENDER: - if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL)) + if (str[i] == '\n') + { + glyph_index = FT_Get_Char_Index(face, ' '); + if (!glyph_index || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) + { + ::warning ("ft_render: skipping missing glyph for character ` '"); + } + else + { + xoffset = 0; + yoffset -= (face->size->metrics.height >> 6); + } + } + else if (FT_Render_Glyph (face->glyph, FT_RENDER_MODE_NORMAL)) ::warning ("ft_render: unable to render glyph for character `%c'", str[i]); else @@ -304,6 +319,14 @@ x0 = xoffset+face->glyph->bitmap_left; y0 = yoffset+face->glyph->bitmap_top; + + // 'w' seems to have a negative -1 + // face->glyph->bitmap_left, this is so we don't + // index out of bound, and assumes we we allocated + // the right amount of horizontal space in the bbox. + if (x0 < 0) + x0 = 0; + for (int r = 0; r < bitmap.rows; r++) for (int c = 0; c < bitmap.width; c++) { @@ -327,43 +350,70 @@ break; case MODE_BBOX: - // width - if (previous) + if (str[i] == '\n') { - FT_Vector delta; - - FT_Get_Kerning (face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); - bbox(2) += (delta.x >> 6); - } - bbox(2) += (face->glyph->advance.x >> 6); - - int asc, desc; - - if (false /*tight*/) + glyph_index = FT_Get_Char_Index(face, ' '); + if (! glyph_index + || FT_Load_Glyph (face, glyph_index, FT_LOAD_DEFAULT)) + { + ::warning ("ft_render: skipping missing glyph for character ` '"); + } + else + { + // Reset the pixel width for this newline, so we don't + // allocate a bounding box larger than the horizontal + // width of the multi-line + box_line_width = 0; + bbox(1) -= (face->size->metrics.height >> 6); + } + } + else { - desc = face->glyph->metrics.horiBearingY - face->glyph->metrics.height; - asc = face->glyph->metrics.horiBearingY; - } - else - { - asc = face->size->metrics.ascender; - desc = face->size->metrics.descender; - } + // width + if (previous) + { + FT_Vector delta; + + FT_Get_Kerning (face, previous, glyph_index, + FT_KERNING_DEFAULT, &delta); + + box_line_width += (delta.x >> 6); + } + + box_line_width += (face->glyph->advance.x >> 6); + + int asc, desc; - asc = yoffset + (asc >> 6); - desc = yoffset + (desc >> 6); + if (false /*tight*/) + { + desc = face->glyph->metrics.horiBearingY - face->glyph->metrics.height; + asc = face->glyph->metrics.horiBearingY; + } + else + { + asc = face->size->metrics.ascender; + desc = face->size->metrics.descender; + } - if (desc < bbox(1)) - { - bbox(3) += (bbox(1) - desc); - bbox(1) = desc; - } - if (asc > (bbox(3)+bbox(1))) - bbox(3) = asc-bbox(1); + asc = yoffset + (asc >> 6); + desc = yoffset + (desc >> 6); + + if (desc < bbox(1)) + { + bbox(3) += (bbox(1) - desc); + bbox(1) = desc; + } + if (asc > (bbox(3)+bbox(1))) + bbox(3) = asc-bbox(1); + if (bbox(2) < box_line_width) + bbox(2) = box_line_width; + } break; } - - previous = glyph_index; + if (str[i] == '\n') + previous = 0; + else + previous = glyph_index; } } }