[PATCH] Haiku: implement font styles
François Revol <[email protected]> Fri, 24 Jan 2014 23:36:51 +0100
| Newsgroups | gmane.editors.qemacs.devel |
|---|---|
| Message-ID | <[email protected]> |
This implements support for font styles on Haiku, including emulating underline (and possibly strikethrough but not tested). We still only use fixed sized font due to missing code in haiku_text_metrics. François. _______________________________________________ Qemacs-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/qemacs-devel
qemacs-haiku-fonts-20140124.patch
(text/x-patch, 2.7 KB)
Index: haiku.cpp
===================================================================
RCS file: /sources/qemacs/qemacs/haiku.cpp,v
retrieving revision 1.7
diff -u -r1.7 haiku.cpp
--- haiku.cpp 23 Jan 2014 17:01:43 -0000 1.7
+++ haiku.cpp 24 Jan 2014 22:33:19 -0000
@@ -668,8 +668,33 @@
if (!font)
return NULL;
- // TODO: use style / size
- BFont *f = new BFont(ctx->font);
+ BFont *f;
+ uint16 face = 0;
+ switch (style & QE_FAMILY_MASK) {
+ default:
+ case QE_FAMILY_FIXED:
+ f = new BFont(be_fixed_font);
+ break;
+ case QE_FAMILY_SANS:
+ case QE_FAMILY_SERIF:
+ /* There isn't a separate default sans and serif font */
+ /* for now just only use fixed font */
+ //f = new BFont(be_plain_font);
+ f = new BFont(be_fixed_font);
+ break;
+ }
+ if (style & QE_STYLE_NORM)
+ face |= B_REGULAR_FACE;
+ if (style & QE_STYLE_BOLD)
+ face |= B_BOLD_FACE;
+ if (style & QE_STYLE_ITALIC)
+ face |= B_ITALIC_FACE;
+ if (style & QE_STYLE_UNDERLINE)
+ face |= B_UNDERSCORE_FACE; // not really supported IIRC
+ if (style & QE_STYLE_LINE_THROUGH)
+ face |= B_STRIKEOUT_FACE; // not really supported IIRC
+ if (face)
+ f->SetFace(face);
font_height height;
f->GetHeight(&height);
@@ -681,9 +706,15 @@
static void haiku_close_font(QEditScreen *s, QEFont **fontp)
{
- if (*fontp) {
- BFont *f = (BFont *)(*fontp)->priv_data;
+ QEFont *font = *fontp;
+
+ if (font) {
+ BFont *f = (BFont *)font->priv_data;
delete f;
+ /* Clear structure to force crash if font is still used after
+ * close_font.
+ */
+ memset(font, 0, sizeof(*font));
qe_free(fontp);
}
}
@@ -733,10 +764,27 @@
cc = str[i];
unicode_to_charset(buf, cc, &charset_utf8);
text << buf;
- //ctx->v->DrawString(buf);
}
ctx->v->DrawString(text.String());
+ /* underline synthesis */
+ if (font->style & (QE_STYLE_UNDERLINE | QE_STYLE_LINE_THROUGH)) {
+ int dy, h, w;
+ BFont *f = (BFont *)font->priv_data;
+ h = (font->descent + 2) / 4 - 1;
+ if (h < 0)
+ h = 0;
+ w = (int)f->StringWidth(text.String()) - 1;
+ if (font->style & QE_STYLE_UNDERLINE) {
+ dy = (font->descent + 1) / 3;
+ ctx->v->FillRect(BRect(x1, y + dy, x1 + w, y + dy + h));
+ }
+ if (font->style & QE_STYLE_LINE_THROUGH) {
+ dy = -(font->ascent / 2 - 1);
+ ctx->v->FillRect(BRect(x1, y + dy, x1 + w, y + dy + h));
+ }
+ }
+
ctx->v->UnlockLooper();
//TextOutW(haiku_ctx.hdc, x1, y - font->ascent, buf, len);