作図ソフト dia の改良版
Revision | eb4f54d0961d70bb9623be1a106c9048b5864d43 (tree) |
---|---|
Zeit | 2008-07-07 01:27:34 |
Autor | Hans Breuer <hans@breu...> |
Commiter | Hans Breuer |
some cleanup and test code to get on the real reason for Dia's notorious
2008-07-06 Hans Breuer <hans@breuer.org>
* lib/font.[hc] : some cleanup and test code to get on the real reason
for Dia's notorious font-size mismatch, see e.g. bug #108293, #345538,
#538499, ... not supposed to change behaviour yet
* samples/font-sizes.dia : new test file using concrete fonts
svn path=/trunk/; revision=4084
@@ -1,5 +1,12 @@ | ||
1 | 1 | 2008-07-06 Hans Breuer <hans@breuer.org> |
2 | 2 | |
3 | + * lib/font.[hc] : some cleanup and test code to get on the real reason | |
4 | + for Dia's notorious font-size mismatch, see e.g. bug #108293, #345538, | |
5 | + #538499, ... not supposed to change behaviour yet | |
6 | + * samples/font-sizes.dia : new test file using concrete fonts | |
7 | + | |
8 | +2008-07-06 Hans Breuer <hans@breuer.org> | |
9 | + | |
3 | 10 | [Patch from Thomas Harding fixing help finally fixing bug #536334] |
4 | 11 | * doc/Makefile.am hardcopies.make : |
5 | 12 | - documentation uninstall was not complete |
@@ -92,15 +92,46 @@ list_families() | ||
92 | 92 | #endif |
93 | 93 | |
94 | 94 | static void |
95 | -dia_font_check_for_font(int font) { | |
95 | +dia_font_check_for_font(int font) | |
96 | +{ | |
96 | 97 | DiaFont *check; |
97 | 98 | PangoFont *loaded; |
99 | + static real size = 1.0; | |
98 | 100 | |
99 | - check = dia_font_new_from_style(font, 1.0); | |
101 | + check = dia_font_new_from_style(font, size); | |
102 | + size += 1.0; | |
100 | 103 | loaded = pango_context_load_font(dia_font_get_context(), |
101 | 104 | check->pfd); |
102 | 105 | if (loaded == NULL) { |
103 | 106 | message_error(_("Can't load font %s.\n"), dia_font_get_family(check)); |
107 | + } else { | |
108 | + PangoFont *font2; | |
109 | + PangoFontDescription *pfd2 = pango_font_description_copy (check->pfd); | |
110 | + PangoFontMetrics *m1, *m2; | |
111 | + real factor; | |
112 | + g_print ("Loaded '%s'\n", pango_font_description_to_string (check->pfd)); | |
113 | + | |
114 | + if (pango_font_description_get_size_is_absolute (check->pfd)) | |
115 | + pango_font_description_set_size (pfd2, pango_font_description_get_size (check->pfd)); | |
116 | + else | |
117 | + pango_font_description_set_absolute_size (pfd2, pango_font_description_get_size (check->pfd)); | |
118 | + | |
119 | + font2 = pango_context_load_font(dia_font_get_context(), pfd2); | |
120 | + | |
121 | + m1 = pango_font_get_metrics (loaded, NULL); | |
122 | + m2 = pango_font_get_metrics (font2, NULL); | |
123 | + | |
124 | + factor = (real)pango_font_metrics_get_ascent (m1) / pango_font_metrics_get_ascent (m2); | |
125 | + g_print ("Magic font-factor %g (ascents = %g / %g)\n", | |
126 | + factor, | |
127 | + (real)pango_font_metrics_get_ascent (m1) / PANGO_SCALE, | |
128 | + (real)pango_font_metrics_get_ascent (m2) / PANGO_SCALE); | |
129 | + | |
130 | + g_object_unref (loaded); | |
131 | + g_object_unref (font2); | |
132 | + pango_font_description_free (pfd2); | |
133 | + pango_font_metrics_unref (m1); | |
134 | + pango_font_metrics_unref (m2); | |
104 | 135 | } |
105 | 136 | } |
106 | 137 |
@@ -118,7 +149,9 @@ dia_font_init(PangoContext* pcontext) | ||
118 | 149 | static GList *pango_contexts = NULL; |
119 | 150 | |
120 | 151 | void |
121 | -dia_font_push_context(PangoContext *pcontext) { | |
152 | +dia_font_push_context(PangoContext *pcontext) | |
153 | +{ | |
154 | + dia_font_init (pcontext); /* not needed, just testing */ | |
122 | 155 | pango_contexts = g_list_prepend(pango_contexts, pango_context); |
123 | 156 | pango_context = pcontext; |
124 | 157 | pango_context_set_language (pango_context, gtk_get_default_language ()); |
@@ -145,6 +178,9 @@ dia_font_get_context() { | ||
145 | 178 | /* This is suggested by new Pango (1.2.4+), but doesn't get us the |
146 | 179 | * right resolution:( |
147 | 180 | dia_font_push_context(pango_ft2_font_map_create_context(pango_ft2_font_map_new())); |
181 | + */ | |
182 | + /* with 96x96 it gives consistent - too big - sizes with the cairo renderer, it was 75x75 with 0.96.x | |
183 | + dia_font_push_context(pango_ft2_get_context(96,96)); | |
148 | 184 | */ |
149 | 185 | dia_font_push_context(pango_ft2_get_context(75,75)); |
150 | 186 | #else |
@@ -293,7 +329,8 @@ dia_pfd_set_slant(PangoFontDescription* pfd, DiaFontSlant fo) { | ||
293 | 329 | } |
294 | 330 | } |
295 | 331 | |
296 | -static void dia_pfd_set_size(PangoFontDescription* pfd, real height) | |
332 | +static void | |
333 | +dia_pfd_set_size(PangoFontDescription* pfd, real height) | |
297 | 334 | { /* inline candidate... */ |
298 | 335 | pango_font_description_set_size(pfd, dcm_to_pdu(height) ); |
299 | 336 | } |
@@ -396,7 +433,10 @@ dia_font_get_height(const DiaFont* font) | ||
396 | 433 | void |
397 | 434 | dia_font_set_height(DiaFont* font, real height) |
398 | 435 | { |
399 | - pango_font_description_set_size(font->pfd, dcm_to_pdu(height)); | |
436 | + dia_pfd_set_size (font->pfd, height); | |
437 | +/* not | |
438 | + pango_font_description_set_size(font->pfd, dcm_to_pdu(height)); | |
439 | + */ | |
400 | 440 | } |
401 | 441 | |
402 | 442 |
@@ -581,10 +621,13 @@ dia_font_build_layout(const char* string, DiaFont* font, real height) | ||
581 | 621 | PangoAttribute* attr; |
582 | 622 | guint length; |
583 | 623 | gchar *desc = NULL; |
624 | + PangoFontDescription *pfd; | |
584 | 625 | |
626 | +/*#define MODIFIES_DIA_FONT */ | |
627 | +#ifdef MODIFIES_DIA_FONT | |
585 | 628 | height *= 0.7; |
586 | 629 | dia_font_set_height(font, height); |
587 | - | |
630 | +#endif | |
588 | 631 | |
589 | 632 | /* This could should account for DPI, but it doesn't do right. Grrr... |
590 | 633 | { |
@@ -603,10 +646,17 @@ dia_font_build_layout(const char* string, DiaFont* font, real height) | ||
603 | 646 | pango_layout_set_text(layout, string, length); |
604 | 647 | |
605 | 648 | list = pango_attr_list_new(); |
649 | +#ifdef MODIFIES_DIA_FONT | |
606 | 650 | desc = g_utf8_strdown(pango_font_description_get_family(font->pfd), -1); |
607 | 651 | pango_font_description_set_family(font->pfd, desc); |
608 | 652 | g_free(desc); |
609 | 653 | attr = pango_attr_font_desc_new(font->pfd); |
654 | +#else | |
655 | + pfd = pango_font_description_copy (font->pfd); | |
656 | + pango_font_description_set_size (pfd, dcm_to_pdu (height) * .7); | |
657 | + attr = pango_attr_font_desc_new(pfd); | |
658 | + pango_font_description_free (pfd); | |
659 | +#endif | |
610 | 660 | attr->start_index = 0; |
611 | 661 | attr->end_index = length; |
612 | 662 | pango_attr_list_insert(list,attr); /* eats attr */ |
@@ -621,15 +671,6 @@ dia_font_build_layout(const char* string, DiaFont* font, real height) | ||
621 | 671 | return layout; |
622 | 672 | } |
623 | 673 | |
624 | -/* ************************************************************************ */ | |
625 | -/* scaled versions of the utility routines */ | |
626 | -/* ************************************************************************ */ | |
627 | - | |
628 | -void | |
629 | -dia_font_set_nominal_zoom_factor(real size_one) | |
630 | -{ global_zoom_factor = size_one; } | |
631 | - | |
632 | - | |
633 | 674 | /** Find the offsets of the individual letters in the iter and place them |
634 | 675 | * in an array. |
635 | 676 | * This currently assumes only one run per iter, which is all we can input. |
@@ -659,7 +700,7 @@ get_string_offsets(PangoLayoutIter *iter, real** offsets, int* n_offsets) | ||
659 | 700 | for (i = 0; i < string->num_glyphs; i++) { |
660 | 701 | PangoGlyphGeometry geom = string->glyphs[i].geometry; |
661 | 702 | |
662 | - (*offsets)[i] = pdu_to_dcm(geom.width) / 20; | |
703 | + (*offsets)[i] = pdu_to_dcm(geom.width) / global_zoom_factor; | |
663 | 704 | } |
664 | 705 | } |
665 | 706 |
@@ -728,16 +769,16 @@ dia_font_get_sizes(const char* string, DiaFont *font, real height, | ||
728 | 769 | } else { |
729 | 770 | non_empty_string = string; |
730 | 771 | } |
731 | - layout = dia_font_build_layout(non_empty_string, font, height * 20); | |
772 | + layout = dia_font_build_layout(non_empty_string, font, height * global_zoom_factor); | |
732 | 773 | |
733 | 774 | /* Only one line here ? */ |
734 | 775 | iter = pango_layout_get_iter(layout); |
735 | 776 | |
736 | 777 | pango_layout_iter_get_line_extents(iter, &ink_rect, &logical_rect); |
737 | 778 | |
738 | - top = pdu_to_dcm(logical_rect.y) / 20; | |
739 | - bottom = pdu_to_dcm(logical_rect.y + logical_rect.height) / 20; | |
740 | - bline = pdu_to_dcm(pango_layout_iter_get_baseline(iter)) / 20; | |
779 | + top = pdu_to_dcm(logical_rect.y) / global_zoom_factor; | |
780 | + bottom = pdu_to_dcm(logical_rect.y + logical_rect.height) / global_zoom_factor; | |
781 | + bline = pdu_to_dcm(pango_layout_iter_get_baseline(iter)) / global_zoom_factor; | |
741 | 782 | |
742 | 783 | get_string_offsets(iter, &offsets, n_offsets); |
743 | 784 | get_layout_offsets(pango_layout_get_line(layout, 0), layout_offsets); |
@@ -764,7 +805,7 @@ dia_font_get_sizes(const char* string, DiaFont *font, real height, | ||
764 | 805 | *width = 0.0; |
765 | 806 | } else { |
766 | 807 | /* take the bigger rectangle to avoid cutting of any part of the string */ |
767 | - *width = pdu_to_dcm(logical_rect.width > ink_rect.width ? logical_rect.width : ink_rect.width) / 20; | |
808 | + *width = pdu_to_dcm(logical_rect.width > ink_rect.width ? logical_rect.width : ink_rect.width) / global_zoom_factor; | |
768 | 809 | } |
769 | 810 | return offsets; |
770 | 811 | } |
@@ -198,9 +198,5 @@ real* dia_font_get_sizes(const char* string, DiaFont *font, real height, | ||
198 | 198 | /* -------- Font and string functions - scaled versions. |
199 | 199 | Use these version in Renderers, exclusively. */ |
200 | 200 | |
201 | - /* Call once at the beginning of a rendering pass, to let dia know | |
202 | - what is 1:1 scale. zoom_factor will then be divided by size_one. */ | |
203 | -void dia_font_set_nominal_zoom_factor(real size_one); | |
204 | - | |
205 | 201 | |
206 | 202 | #endif /* FONT_H */ |