diff --git a/unix/OLD_drawtext.c b/unix/OLD_drawtext.c index 0626b6be..dbd2d709 100644 --- a/unix/OLD_drawtext.c +++ b/unix/OLD_drawtext.c @@ -225,25 +225,3 @@ void caretDrawParams(uiDrawContext *c, double height, struct caretDrawParams *p) p->xoff = xoff; p->width = width; } - -// TODO split this and the other font description stuff into their own file? -void fontdescFromPangoFontDescription(PangoFontDescription *pdesc, uiDrawFontDescriptor *uidesc) -{ - PangoStyle pitalic; - PangoStretch pstretch; - - uidesc->Family = uiUnixStrdupText(pango_font_description_get_family(pdesc)); - pitalic = pango_font_description_get_style(pdesc); - // TODO reverse the above misalignment if it is corrected - uidesc->Weight = pango_font_description_get_weight(pdesc); - pstretch = pango_font_description_get_stretch(pdesc); - // absolute size does not matter because, as above, 1 device unit == 1 cairo point - uidesc->Size = pango_units_to_double(pango_font_description_get_size(pdesc)); - - for (uidesc->Italic = uiDrawTextItalicNormal; uidesc->Italic < uiDrawTextItalicItalic; uidesc->Italic++) - if (pangoItalics[uidesc->Italic] == pitalic) - break; - for (uidesc->Stretch = uiDrawTextStretchUltraCondensed; uidesc->Stretch < uiDrawTextStretchUltraExpanded; uidesc->Stretch++) - if (pangoStretches[uidesc->Stretch] == pstretch) - break; -} diff --git a/unix/attrstr.h b/unix/attrstr.h index 5fd072c2..1988fe86 100644 --- a/unix/attrstr.h +++ b/unix/attrstr.h @@ -14,6 +14,7 @@ extern PangoWeight uiprivWeightToPangoWeight(uiTextWeight w); extern PangoStyle uiprivItalicToPangoStyle(uiTextItalic i); extern PangoStretch uiprivStretchToPangoStretch(uiTextStretch s); extern PangoFontDescription *uiprivFontDescriptorToPangoFontDescription(const uiFontDescriptor *uidesc); +extern void uiprivFontDescriptorFromPangoFontDescription(PangoFontDescription *pdesc, uiDrawFontDescriptor *uidesc); // attrstr.c extern PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p, GPtrArray **backgroundParams); diff --git a/unix/OLD_fontbutton.c b/unix/fontbutton.c similarity index 92% rename from unix/OLD_fontbutton.c rename to unix/fontbutton.c index 9a2552b1..3b4a0425 100644 --- a/unix/OLD_fontbutton.c +++ b/unix/fontbutton.c @@ -1,5 +1,6 @@ // 14 april 2016 #include "uipriv_unix.h" +#include "attrstr.h" struct uiFontButton { uiUnixControl c; @@ -31,8 +32,8 @@ void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc) PangoFontDescription *pdesc; pdesc = gtk_font_chooser_get_font_desc(b->fc); - fontdescFromPangoFontDescription(pdesc, desc); - // desc is transfer-full and thus is a copy + uiprivFontDescriptorFromPangoFontDescription(pdesc, desc); + // pdesc is transfer-full and thus is a copy pango_font_description_free(pdesc); } diff --git a/unix/fontmatch.c b/unix/fontmatch.c index 05523c24..c55c77a2 100644 --- a/unix/fontmatch.c +++ b/unix/fontmatch.c @@ -53,3 +53,24 @@ PangoFontDescription *uiprivFontDescriptorToPangoFontDescription(const uiFontDes pango_font_description_set_stretch(desc, uiprivStretchToPangoStretch(uidesc->Stretch)); return desc; } + +void uiprivFontDescriptorFromPangoFontDescription(PangoFontDescription *pdesc, uiDrawFontDescriptor *uidesc) +{ + PangoStyle pitalic; + PangoStretch pstretch; + + uidesc->Family = uiUnixStrdupText(pango_font_description_get_family(pdesc)); + pitalic = pango_font_description_get_style(pdesc); + // TODO reverse the above misalignment if it is corrected + uidesc->Weight = pango_font_description_get_weight(pdesc); + pstretch = pango_font_description_get_stretch(pdesc); + // absolute size does not matter because, as above, 1 device unit == 1 cairo point + uidesc->Size = pango_units_to_double(pango_font_description_get_size(pdesc)); + + for (uidesc->Italic = uiDrawTextItalicNormal; uidesc->Italic < uiDrawTextItalicItalic; uidesc->Italic++) + if (pangoItalics[uidesc->Italic] == pitalic) + break; + for (uidesc->Stretch = uiDrawTextStretchUltraCondensed; uidesc->Stretch < uiDrawTextStretchUltraExpanded; uidesc->Stretch++) + if (pangoStretches[uidesc->Stretch] == pstretch) + break; +}