Mercurial > hg > octave-lyh
comparison src/txt-eng-ft.cc @ 11455:2be9e22796d2
improvements in text-extent calculation
author | Konstantinos Poulios <logari81@googlemail.com> |
---|---|
date | Thu, 06 Jan 2011 20:46:03 +0100 |
parents | f88e3d5d88e2 |
children | fd0a3ac60b0e |
comparison
equal
deleted
inserted
replaced
11454:d7a964a5c57c | 11455:2be9e22796d2 |
---|---|
201 if (face) | 201 if (face) |
202 FT_Done_Face (face); | 202 FT_Done_Face (face); |
203 } | 203 } |
204 | 204 |
205 void | 205 void |
206 ft_render::set_font (const base_properties& props) | 206 ft_render::set_font (const std::string& name, const std::string& weight, |
207 const std::string& angle, double size) | |
207 { | 208 { |
208 if (face) | 209 if (face) |
209 FT_Done_Face (face); | 210 FT_Done_Face (face); |
210 | 211 |
211 // FIXME: take "fontunits" into account | 212 // FIXME: take "fontunits" into account |
212 double font_size = props.get ("fontsize").double_value (); | 213 face = ft_manager::get_font (name, weight, angle, size); |
213 | |
214 face = ft_manager::get_font (props.get ("fontname").string_value (), | |
215 props.get ("fontweight").string_value (), | |
216 props.get ("fontangle").string_value (), | |
217 font_size); | |
218 | 214 |
219 if (face) | 215 if (face) |
220 { | 216 { |
221 if (FT_Set_Char_Size (face, 0, font_size*64, 0, 0)) | 217 if (FT_Set_Char_Size (face, 0, size*64, 0, 0)) |
222 ::warning ("ft_render: unable to set font size to %d", font_size); | 218 ::warning ("ft_render: unable to set font size to %d", size); |
223 } | 219 } |
224 else | 220 else |
225 ::warning ("ft_render: unable to load appropriate font"); | 221 ::warning ("ft_render: unable to load appropriate font"); |
226 } | 222 } |
227 | 223 |
480 return ROTATION_270; | 476 return ROTATION_270; |
481 else | 477 else |
482 return ROTATION_0; | 478 return ROTATION_0; |
483 } | 479 } |
484 | 480 |
481 void | |
482 ft_render::text_to_pixels (const std::string& txt, | |
483 uint8NDArray& pixels_, Matrix& box, | |
484 int halign, int valign, double rotation) | |
485 { | |
486 // FIXME: clip "rotation" between 0 and 360 | |
487 int rot_mode = rotation_to_mode (rotation); | |
488 | |
489 text_element *elt = text_parser_none ().parse (txt); | |
490 pixels_ = render (elt, box, rot_mode); | |
491 delete elt; | |
492 | |
493 if (pixels_.numel () == 0) | |
494 { | |
495 // nothing to render | |
496 return; | |
497 } | |
498 | |
499 switch (halign) | |
500 { | |
501 default: box(0) = 0; break; | |
502 case 1: box(0) = -box(2)/2; break; | |
503 case 2: box(0) = -box(2); break; | |
504 } | |
505 switch (valign) | |
506 { | |
507 default: box(1) = 0; break; | |
508 case 1: box(1) = -box(3)/2; break; | |
509 case 2: box(1) = -box(3); break; | |
510 case 3: break; | |
511 } | |
512 | |
513 switch (rot_mode) | |
514 { | |
515 case ROTATION_90: | |
516 std::swap (box(0), box(1)); | |
517 std::swap (box(2), box(3)); | |
518 box(0) = -box(0)-box(2); | |
519 break; | |
520 case ROTATION_180: | |
521 box(0) = -box(0)-box(2); | |
522 box(1) = -box(1)-box(3); | |
523 break; | |
524 case ROTATION_270: | |
525 std::swap (box(0), box(1)); | |
526 std::swap (box(2), box(3)); | |
527 box(1) = -box(1)-box(3); | |
528 break; | |
529 } | |
530 } | |
531 | |
485 #endif // HAVE_FREETYPE | 532 #endif // HAVE_FREETYPE |