[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs haiku.cpp
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs haiku.cpp |
Date: |
Wed, 29 Jan 2014 22:53:59 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/01/29 22:53:59
Modified files:
. : haiku.cpp
Log message:
add support for font styles in haiku by Francois Revol
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/haiku.cpp?cvsroot=qemacs&r1=1.7&r2=1.8
Patches:
Index: haiku.cpp
===================================================================
RCS file: /sources/qemacs/qemacs/haiku.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- haiku.cpp 23 Jan 2014 17:01:43 -0000 1.7
+++ haiku.cpp 29 Jan 2014 22:53:57 -0000 1.8
@@ -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);