Created a new file for the font matching code.
This commit is contained in:
parent
24d2220fe5
commit
5939c3203d
|
@ -24,6 +24,7 @@ list(APPEND _LIBUI_SOURCES
|
||||||
unix/editablecombo.c
|
unix/editablecombo.c
|
||||||
unix/entry.c
|
unix/entry.c
|
||||||
unix/fontbutton.c
|
unix/fontbutton.c
|
||||||
|
unix/fontmatch.c
|
||||||
unix/form.c
|
unix/form.c
|
||||||
unix/future.c
|
unix/future.c
|
||||||
unix/graphemes.c
|
unix/graphemes.c
|
||||||
|
|
|
@ -68,15 +68,15 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
|
||||||
case uiAttributeTypeWeight:
|
case uiAttributeTypeWeight:
|
||||||
// TODO reverse the misalignment from drawtext.c if it is corrected
|
// TODO reverse the misalignment from drawtext.c if it is corrected
|
||||||
addattr(p, start, end,
|
addattr(p, start, end,
|
||||||
pango_attr_weight_new((PangoWeight) uiAttributeWeight(attr)));
|
pango_attr_weight_new(uiprivWeightToPangoWeight(uiAttributeWeight(attr))));
|
||||||
break;
|
break;
|
||||||
case uiAttributeTypeItalic:
|
case uiAttributeTypeItalic:
|
||||||
addattr(p, start, end,
|
addattr(p, start, end,
|
||||||
pango_attr_style_new(pangoItalics[uiAttributeItalic(attr)]));
|
pango_attr_style_new(uiprivItalicToPangoStyle(uiAttributeItalic(attr))));
|
||||||
break;
|
break;
|
||||||
case uiAttributeTypeStretch:
|
case uiAttributeTypeStretch:
|
||||||
addattr(p, start, end,
|
addattr(p, start, end,
|
||||||
pango_attr_stretch_new(pangoStretches[uiAttributeStretch(attr)]));
|
pango_attr_stretch_new(uiprivStretchToPangoStretch(uiAttributeStretch(attr))));
|
||||||
break;
|
break;
|
||||||
case uiAttributeTypeColor:
|
case uiAttributeTypeColor:
|
||||||
uiAttributeColor(attr, &r, &g, &b, &a);
|
uiAttributeColor(attr, &r, &g, &b, &a);
|
||||||
|
|
|
@ -9,6 +9,12 @@
|
||||||
// opentype.c
|
// opentype.c
|
||||||
extern GString *uiprivOpenTypeFeaturesToPangoCSSFeaturesString(const uiOpenTypeFeatures *otf);
|
extern GString *uiprivOpenTypeFeaturesToPangoCSSFeaturesString(const uiOpenTypeFeatures *otf);
|
||||||
|
|
||||||
|
// fontmatch.c
|
||||||
|
extern PangoWeight uiprivWeightToPangoWeight(uiTextWeight w);
|
||||||
|
extern PangoStyle uiprivItalicToPangoStyle(uiTextItalic i);
|
||||||
|
extern PangoStretch uiprivStretchToPangoStretch(uiTextStretch s);
|
||||||
|
extern PangoFontDescription *uiprivFontDescriptorToPangoFontDescription(const uiFontDescriptor *uidesc);
|
||||||
|
|
||||||
// attrstr.c
|
// attrstr.c
|
||||||
extern PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p, GPtrArray **backgroundParams);
|
extern PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p, GPtrArray **backgroundParams);
|
||||||
|
|
||||||
|
@ -23,6 +29,3 @@ struct uiprivDrawTextBackgroundParams {
|
||||||
double b;
|
double b;
|
||||||
double a;
|
double a;
|
||||||
};
|
};
|
||||||
// TODO move this to a fontmatch.c
|
|
||||||
extern const PangoStyle uiprivPangoItalics[];
|
|
||||||
extern const PangoStretch uiprivPangoStretches[];
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
xx 11 march 2018
|
// 11 march 2018
|
||||||
#import "uipriv_unix.h"
|
#import "uipriv_unix.h"
|
||||||
#import "draw.h"
|
#import "draw.h"
|
||||||
#import "attrstr.h"
|
#import "attrstr.h"
|
||||||
|
@ -14,24 +14,6 @@ struct uiDrawTextLayout {
|
||||||
// so let's use gdk_pango_context_get() instead; even though it's for the default screen only, it's good enough for us
|
// so let's use gdk_pango_context_get() instead; even though it's for the default screen only, it's good enough for us
|
||||||
#define mkGenericPangoCairoContext() (gdk_pango_context_get())
|
#define mkGenericPangoCairoContext() (gdk_pango_context_get())
|
||||||
|
|
||||||
const PangoStyle uiprivPangoItalics[] = {
|
|
||||||
[uiTextItalicNormal] = PANGO_STYLE_NORMAL,
|
|
||||||
[uiTextItalicOblique] = PANGO_STYLE_OBLIQUE,
|
|
||||||
[uiTextItalicItalic] = PANGO_STYLE_ITALIC,
|
|
||||||
};
|
|
||||||
|
|
||||||
const PangoStretch uiprivPangoStretches[] = {
|
|
||||||
[uiTextStretchUltraCondensed] = PANGO_STRETCH_ULTRA_CONDENSED,
|
|
||||||
[uiTextStretchExtraCondensed] = PANGO_STRETCH_EXTRA_CONDENSED,
|
|
||||||
[uiTextStretchCondensed] = PANGO_STRETCH_CONDENSED,
|
|
||||||
[uiTextStretchSemiCondensed] = PANGO_STRETCH_SEMI_CONDENSED,
|
|
||||||
[uiTextStretchNormal] = PANGO_STRETCH_NORMAL,
|
|
||||||
[uiTextStretchSemiExpanded] = PANGO_STRETCH_SEMI_EXPANDED,
|
|
||||||
[uiTextStretchExpanded] = PANGO_STRETCH_EXPANDED,
|
|
||||||
[uiTextStretchExtraExpanded] = PANGO_STRETCH_EXTRA_EXPANDED,
|
|
||||||
[uiTextStretchUltraExpanded] = PANGO_STRETCH_ULTRA_EXPANDED,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const PangoAlignment pangoAligns[] = {
|
static const PangoAlignment pangoAligns[] = {
|
||||||
[uiDrawTextAlignLeft] = PANGO_ALIGN_LEFT,
|
[uiDrawTextAlignLeft] = PANGO_ALIGN_LEFT,
|
||||||
[uiDrawTextAlignCenter] = PANGO_ALIGN_CENTER,
|
[uiDrawTextAlignCenter] = PANGO_ALIGN_CENTER,
|
||||||
|
@ -57,18 +39,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
// this is safe; pango_layout_set_text() copies the string
|
// this is safe; pango_layout_set_text() copies the string
|
||||||
pango_layout_set_text(tl->layout, uiAttributedStringString(p->String), -1);
|
pango_layout_set_text(tl->layout, uiAttributedStringString(p->String), -1);
|
||||||
|
|
||||||
desc = pango_font_description_new();
|
desc = uiprivFontDescriptorToPangoFontDescription(p->DefaultFont);
|
||||||
pango_font_description_set_family(desc, p->DefaultFont->Family);
|
|
||||||
pango_font_description_set_style(desc, uiprivPangoItalics[p->DefaultFont->Italic]);
|
|
||||||
// for the most part, pango weights correlate to ours
|
|
||||||
// the differences:
|
|
||||||
// - Book — libui: 350, Pango: 380
|
|
||||||
// - Ultra Heavy — libui: 950, Pango: 1000
|
|
||||||
// TODO figure out what to do about this misalignment
|
|
||||||
pango_font_description_set_weight(desc, p->DefaultFont->Weight);
|
|
||||||
pango_font_description_set_stretch(desc, uiprivPangoStretches[p->DefaultFont->Stretch]);
|
|
||||||
// see https://developer.gnome.org/pango/1.30/pango-Fonts.html#pango-font-description-set-size and https://developer.gnome.org/pango/1.30/pango-Glyph-Storage.html#pango-units-from-double
|
|
||||||
pango_font_description_set_size(desc, pango_units_from_double(p->DefaultFont->Size));
|
|
||||||
pango_layout_set_font_description(tl->layout, desc);
|
pango_layout_set_font_description(tl->layout, desc);
|
||||||
// this is safe; the description is copied
|
// this is safe; the description is copied
|
||||||
pango_font_description_free(desc);
|
pango_font_description_free(desc);
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
// 11 march 2018
|
||||||
|
#include "uipriv_unix.h"
|
||||||
|
#include "attrstr.h"
|
||||||
|
|
||||||
|
static const PangoStyle pangoItalics[] = {
|
||||||
|
[uiTextItalicNormal] = PANGO_STYLE_NORMAL,
|
||||||
|
[uiTextItalicOblique] = PANGO_STYLE_OBLIQUE,
|
||||||
|
[uiTextItalicItalic] = PANGO_STYLE_ITALIC,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const PangoStretch pangoStretches[] = {
|
||||||
|
[uiTextStretchUltraCondensed] = PANGO_STRETCH_ULTRA_CONDENSED,
|
||||||
|
[uiTextStretchExtraCondensed] = PANGO_STRETCH_EXTRA_CONDENSED,
|
||||||
|
[uiTextStretchCondensed] = PANGO_STRETCH_CONDENSED,
|
||||||
|
[uiTextStretchSemiCondensed] = PANGO_STRETCH_SEMI_CONDENSED,
|
||||||
|
[uiTextStretchNormal] = PANGO_STRETCH_NORMAL,
|
||||||
|
[uiTextStretchSemiExpanded] = PANGO_STRETCH_SEMI_EXPANDED,
|
||||||
|
[uiTextStretchExpanded] = PANGO_STRETCH_EXPANDED,
|
||||||
|
[uiTextStretchExtraExpanded] = PANGO_STRETCH_EXTRA_EXPANDED,
|
||||||
|
[uiTextStretchUltraExpanded] = PANGO_STRETCH_ULTRA_EXPANDED,
|
||||||
|
};
|
||||||
|
|
||||||
|
// for the most part, pango weights correlate to ours
|
||||||
|
// the differences:
|
||||||
|
// - Book — libui: 350, Pango: 380
|
||||||
|
// - Ultra Heavy — libui: 950, Pango: 1000
|
||||||
|
// TODO figure out what to do about this misalignment
|
||||||
|
PangoWeight uiprivWeightToPangoWeight(uiTextWeight w)
|
||||||
|
{
|
||||||
|
return (PangoWeight) w;
|
||||||
|
}
|
||||||
|
|
||||||
|
PangoStyle uiprivItalicToPangoStyle(uiTextItalic i)
|
||||||
|
{
|
||||||
|
return pangoItalics[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
PangoStretch uiprivStretchToPangoStretch(uiTextStretch s)
|
||||||
|
{
|
||||||
|
return pangoStretches[s];
|
||||||
|
}
|
||||||
|
|
||||||
|
PangoFontDescription *uiprivFontDescriptorToPangoFontDescription(const uiFontDescriptor *uidesc)
|
||||||
|
{
|
||||||
|
PangoFontDescriptor *desc;
|
||||||
|
|
||||||
|
desc = pango_font_description_new();
|
||||||
|
pango_font_description_set_family(desc, uidesc->Family);
|
||||||
|
// see https://developer.gnome.org/pango/1.30/pango-Fonts.html#pango-font-description-set-size and https://developer.gnome.org/pango/1.30/pango-Glyph-Storage.html#pango-units-from-double
|
||||||
|
pango_font_description_set_size(desc, pango_units_from_double(uidesc->Size));
|
||||||
|
pango_font_description_set_weight(desc, uiprivWeightToPangoWeight(uidesc->Weight));
|
||||||
|
pango_font_description_set_style(desc, uiprivItalicToPangoStyle(uidesc->Italic));
|
||||||
|
pango_font_description_set_stretch(desc, uiprivStretchToPangoStretch(uidesc->Stretch));
|
||||||
|
return desc;
|
||||||
|
}
|
Loading…
Reference in New Issue