summaryrefslogtreecommitdiff
path: root/src/haiku_font_support.cc
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-05-05 09:46:05 +0000
committerPo Lu <luangruo@yahoo.com>2022-05-05 09:46:05 +0000
commit1468eef301a59346adc47ef19a740f4e2c3737a2 (patch)
treeee16c08d185100385231849da505310cf6e9ff5e /src/haiku_font_support.cc
parent30caeb789659441f8feb76b24f3d0b1f60125085 (diff)
downloademacs-1468eef301a59346adc47ef19a740f4e2c3737a2.tar.gz
Speed up opening fonts on Haiku
* src/font.h (font_property_index): Note that some font drivers use the extra data in a font entity to store driver-specific information. * src/haiku_font_support.cc (BFont_find): Set font indices. (be_open_font_at_index): New function. (BFont_open_pattern): Clean up coding style. * src/haiku_support.h (enum haiku_font_specification) (struct haiku_font_pattern): New fields and specifications for indices. * src/haikufont.c (haikufont_pattern_to_entity, haikufont_open): Use indices to open fonts if available in the extra data.
Diffstat (limited to 'src/haiku_font_support.cc')
-rw-r--r--src/haiku_font_support.cc118
1 files changed, 90 insertions, 28 deletions
diff --git a/src/haiku_font_support.cc b/src/haiku_font_support.cc
index 339634f01be..ca6aaf71204 100644
--- a/src/haiku_font_support.cc
+++ b/src/haiku_font_support.cc
@@ -574,18 +574,21 @@ BFont_find (struct haiku_font_pattern *pt)
font_family name;
font_style sname;
uint32 flags;
- int sty_count;
- int fam_count = count_font_families ();
+ int sty_count, fam_count, si, fi;
+ struct haiku_font_pattern *p, *head, *n;
+ bool oblique_seen_p;
- for (int fi = 0; fi < fam_count; ++fi)
+ fam_count = count_font_families ();
+
+ for (fi = 0; fi < fam_count; ++fi)
{
if (get_font_family (fi, &name, &flags) == B_OK)
{
sty_count = count_font_styles (name);
- if (!sty_count &&
- font_family_style_matches_p (name, NULL, flags, pt))
+ if (!sty_count
+ && font_family_style_matches_p (name, NULL, flags, pt))
{
- struct haiku_font_pattern *p = new struct haiku_font_pattern;
+ p = new struct haiku_font_pattern;
p->specified = 0;
p->oblique_seen_p = 1;
haiku_font_fill_pattern (p, name, NULL, flags);
@@ -598,11 +601,11 @@ BFont_find (struct haiku_font_pattern *pt)
}
else if (sty_count)
{
- for (int si = 0; si < sty_count; ++si)
+ for (si = 0; si < sty_count; ++si)
{
- int oblique_seen_p = 0;
- struct haiku_font_pattern *head = r;
- struct haiku_font_pattern *p = NULL;
+ oblique_seen_p = 0;
+ head = r;
+ p = NULL;
if (get_font_style (name, si, &sname, &flags) == B_OK)
{
@@ -611,8 +614,18 @@ BFont_find (struct haiku_font_pattern *pt)
p = new struct haiku_font_pattern;
p->specified = 0;
haiku_font_fill_pattern (p, name, (char *) &sname, flags);
- if (p->specified & FSPEC_SLANT &&
- ((p->slant == SLANT_OBLIQUE) || (p->slant == SLANT_ITALIC)))
+
+ /* Add the indices to this font now so we
+ won't have to loop over each font in
+ order to open it later. */
+
+ p->specified |= FSPEC_INDICES;
+ p->family_index = fi;
+ p->style_index = si;
+
+ if (p->specified & FSPEC_SLANT
+ && (p->slant == SLANT_OBLIQUE
+ || p->slant == SLANT_ITALIC))
oblique_seen_p = 1;
p->next = r;
@@ -627,9 +640,7 @@ BFont_find (struct haiku_font_pattern *pt)
p->last = NULL;
for (; head; head = head->last)
- {
- head->oblique_seen_p = oblique_seen_p;
- }
+ head->oblique_seen_p = oblique_seen_p;
}
}
}
@@ -642,13 +653,18 @@ BFont_find (struct haiku_font_pattern *pt)
if (!(pt->specified & FSPEC_SLANT))
{
/* r->last is invalid from here onwards. */
- for (struct haiku_font_pattern *p = r; p;)
+ for (p = r; p;)
{
if (!p->oblique_seen_p)
{
- struct haiku_font_pattern *n = new haiku_font_pattern;
+ n = new haiku_font_pattern;
*n = *p;
+
n->slant = SLANT_OBLIQUE;
+
+ /* Opening a font by its indices doesn't provide enough
+ information to synthesize the oblique font later. */
+ n->specified &= ~FSPEC_INDICES;
p->next = n;
p = p->next_family;
}
@@ -660,26 +676,68 @@ BFont_find (struct haiku_font_pattern *pt)
return r;
}
+/* Find and open a font with the family at FAMILY and the style at
+ STYLE, and set its size to SIZE. Value is NULL if opening the font
+ failed. */
+void *
+be_open_font_at_index (int family, int style, float size)
+{
+ font_family family_name;
+ font_style style_name;
+ uint32 flags;
+ status_t rc;
+ BFont *font;
+
+ rc = get_font_family (family, &family_name, &flags);
+
+ if (rc != B_OK)
+ return NULL;
+
+ rc = get_font_style (family_name, style, &style_name, &flags);
+
+ if (rc != B_OK)
+ return NULL;
+
+ font = new BFont;
+
+ rc = font->SetFamilyAndStyle (family_name, style_name);
+
+ if (rc != B_OK)
+ {
+ delete font;
+ return NULL;
+ }
+
+ font->SetSize (size);
+ font->SetEncoding (B_UNICODE_UTF8);
+ font->SetSpacing (B_BITMAP_SPACING);
+ return font;
+}
+
/* Find and open a font matching the pattern PAT, which must have its
family set. */
int
BFont_open_pattern (struct haiku_font_pattern *pat, void **font, float size)
{
- int sty_count;
+ int sty_count, si, code;
font_family name;
font_style sname;
+ BFont *ft;
uint32 flags = 0;
+ struct haiku_font_pattern copy;
+
if (!(pat->specified & FSPEC_FAMILY))
return 1;
+
strncpy (name, pat->family, sizeof name - 1);
name[sizeof name - 1] = '\0';
sty_count = count_font_styles (name);
- if (!sty_count &&
- font_family_style_matches_p (name, NULL, flags, pat, 1))
+ if (!sty_count
+ && font_family_style_matches_p (name, NULL, flags, pat, 1))
{
- BFont *ft = new BFont;
+ ft = new BFont;
ft->SetSize (size);
ft->SetEncoding (B_UNICODE_UTF8);
ft->SetSpacing (B_BITMAP_SPACING);
@@ -694,12 +752,13 @@ BFont_open_pattern (struct haiku_font_pattern *pat, void **font, float size)
}
else if (sty_count)
{
- for (int si = 0; si < sty_count; ++si)
+ for (si = 0; si < sty_count; ++si)
{
- if (get_font_style (name, si, &sname, &flags) == B_OK &&
- font_family_style_matches_p (name, (char *) &sname, flags, pat))
+ if (get_font_style (name, si, &sname, &flags) == B_OK
+ && font_family_style_matches_p (name, (char *) &sname,
+ flags, pat))
{
- BFont *ft = new BFont;
+ ft = new BFont;
ft->SetSize (size);
ft->SetEncoding (B_UNICODE_UTF8);
ft->SetSpacing (B_BITMAP_SPACING);
@@ -709,6 +768,7 @@ BFont_open_pattern (struct haiku_font_pattern *pat, void **font, float size)
delete ft;
return 1;
}
+
*font = (void *) ft;
return 0;
}
@@ -717,12 +777,14 @@ BFont_open_pattern (struct haiku_font_pattern *pat, void **font, float size)
if (pat->specified & FSPEC_SLANT && pat->slant == SLANT_OBLIQUE)
{
- struct haiku_font_pattern copy = *pat;
+ copy = *pat;
copy.slant = SLANT_REGULAR;
- int code = BFont_open_pattern (&copy, font, size);
+ code = BFont_open_pattern (&copy, font, size);
+
if (code)
return code;
- BFont *ft = (BFont *) *font;
+
+ ft = (BFont *) *font;
/* XXX Font measurements don't respect shear. Haiku bug?
This apparently worked in BeOS.
ft->SetShear (100.0); */