• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作図ソフト dia の改良版


Commit MetaInfo

Révisioneb4f54d0961d70bb9623be1a106c9048b5864d43 (tree)
l'heure2008-07-07 01:27:34
AuteurHans Breuer <hans@breu...>
CommiterHans Breuer

Message de Log

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

Change Summary

Modification

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
11 2008-07-06 Hans Breuer <hans@breuer.org>
22
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+
310 [Patch from Thomas Harding fixing help finally fixing bug #536334]
411 * doc/Makefile.am hardcopies.make :
512 - documentation uninstall was not complete
--- a/lib/font.c
+++ b/lib/font.c
@@ -92,15 +92,46 @@ list_families()
9292 #endif
9393
9494 static void
95-dia_font_check_for_font(int font) {
95+dia_font_check_for_font(int font)
96+{
9697 DiaFont *check;
9798 PangoFont *loaded;
99+ static real size = 1.0;
98100
99- check = dia_font_new_from_style(font, 1.0);
101+ check = dia_font_new_from_style(font, size);
102+ size += 1.0;
100103 loaded = pango_context_load_font(dia_font_get_context(),
101104 check->pfd);
102105 if (loaded == NULL) {
103106 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);
104135 }
105136 }
106137
@@ -118,7 +149,9 @@ dia_font_init(PangoContext* pcontext)
118149 static GList *pango_contexts = NULL;
119150
120151 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 */
122155 pango_contexts = g_list_prepend(pango_contexts, pango_context);
123156 pango_context = pcontext;
124157 pango_context_set_language (pango_context, gtk_get_default_language ());
@@ -145,6 +178,9 @@ dia_font_get_context() {
145178 /* This is suggested by new Pango (1.2.4+), but doesn't get us the
146179 * right resolution:(
147180 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));
148184 */
149185 dia_font_push_context(pango_ft2_get_context(75,75));
150186 #else
@@ -293,7 +329,8 @@ dia_pfd_set_slant(PangoFontDescription* pfd, DiaFontSlant fo) {
293329 }
294330 }
295331
296-static void dia_pfd_set_size(PangoFontDescription* pfd, real height)
332+static void
333+dia_pfd_set_size(PangoFontDescription* pfd, real height)
297334 { /* inline candidate... */
298335 pango_font_description_set_size(pfd, dcm_to_pdu(height) );
299336 }
@@ -396,7 +433,10 @@ dia_font_get_height(const DiaFont* font)
396433 void
397434 dia_font_set_height(DiaFont* font, real height)
398435 {
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+ */
400440 }
401441
402442
@@ -581,10 +621,13 @@ dia_font_build_layout(const char* string, DiaFont* font, real height)
581621 PangoAttribute* attr;
582622 guint length;
583623 gchar *desc = NULL;
624+ PangoFontDescription *pfd;
584625
626+/*#define MODIFIES_DIA_FONT */
627+#ifdef MODIFIES_DIA_FONT
585628 height *= 0.7;
586629 dia_font_set_height(font, height);
587-
630+#endif
588631
589632 /* This could should account for DPI, but it doesn't do right. Grrr...
590633 {
@@ -603,10 +646,17 @@ dia_font_build_layout(const char* string, DiaFont* font, real height)
603646 pango_layout_set_text(layout, string, length);
604647
605648 list = pango_attr_list_new();
649+#ifdef MODIFIES_DIA_FONT
606650 desc = g_utf8_strdown(pango_font_description_get_family(font->pfd), -1);
607651 pango_font_description_set_family(font->pfd, desc);
608652 g_free(desc);
609653 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
610660 attr->start_index = 0;
611661 attr->end_index = length;
612662 pango_attr_list_insert(list,attr); /* eats attr */
@@ -621,15 +671,6 @@ dia_font_build_layout(const char* string, DiaFont* font, real height)
621671 return layout;
622672 }
623673
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-
633674 /** Find the offsets of the individual letters in the iter and place them
634675 * in an array.
635676 * 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)
659700 for (i = 0; i < string->num_glyphs; i++) {
660701 PangoGlyphGeometry geom = string->glyphs[i].geometry;
661702
662- (*offsets)[i] = pdu_to_dcm(geom.width) / 20;
703+ (*offsets)[i] = pdu_to_dcm(geom.width) / global_zoom_factor;
663704 }
664705 }
665706
@@ -728,16 +769,16 @@ dia_font_get_sizes(const char* string, DiaFont *font, real height,
728769 } else {
729770 non_empty_string = string;
730771 }
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);
732773
733774 /* Only one line here ? */
734775 iter = pango_layout_get_iter(layout);
735776
736777 pango_layout_iter_get_line_extents(iter, &ink_rect, &logical_rect);
737778
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;
741782
742783 get_string_offsets(iter, &offsets, n_offsets);
743784 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,
764805 *width = 0.0;
765806 } else {
766807 /* 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;
768809 }
769810 return offsets;
770811 }
--- a/lib/font.h
+++ b/lib/font.h
@@ -198,9 +198,5 @@ real* dia_font_get_sizes(const char* string, DiaFont *font, real height,
198198 /* -------- Font and string functions - scaled versions.
199199 Use these version in Renderers, exclusively. */
200200
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-
205201
206202 #endif /* FONT_H */
Binary files /dev/null and b/samples/font-sizes.dia differ