aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
Diffstat (limited to 'dw')
-rw-r--r--dw/fltkplatform.cc49
-rw-r--r--dw/fltkui.cc3
-rw-r--r--dw/fltkviewbase.cc44
-rw-r--r--dw/style.cc3
-rw-r--r--dw/style.hh8
-rw-r--r--dw/textblock.cc16
-rw-r--r--dw/ui.cc14
-rw-r--r--dw/ui.hh2
8 files changed, 102 insertions, 37 deletions
diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc
index 97e10710..010aa113 100644
--- a/dw/fltkplatform.cc
+++ b/dw/fltkplatform.cc
@@ -17,6 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdio.h>
+#include <wchar.h>
+#include <wctype.h>
#include "../lout/msg.h"
#include "fltkcore.hh"
@@ -28,7 +31,6 @@
#include <fltk/InvisibleBox.h>
#include <fltk/Tooltip.h>
#include <fltk/utf.h>
-#include <stdio.h>
namespace dw {
namespace fltk {
@@ -351,20 +353,45 @@ void FltkPlatform::detachView (core::View *view)
int FltkPlatform::textWidth (core::style::Font *font, const char *text,
int len)
{
- int width;
+ char chbuf[4];
+ wchar_t wc, wcu;
+ int width = 0;
FltkFont *ff = (FltkFont*) font;
- setfont (ff->font, ff->size);
- width = (int) getwidth (text, len);
-
- if (font->letterSpacing) {
- int curr = 0, next = 0;
-
- while (next < len) {
+ int curr = 0, next = 0, nb;
+
+ if (font->fontVariant == 1) {
+ int sc_fontsize = lout::misc::roundInt(ff->size * 0.78);
+ for (curr = 0; next < len; curr = next) {
next = nextGlyph(text, curr);
- width += font->letterSpacing;
- curr = next;
+ wc = utf8decode(text + curr, text + next, &nb);
+ if ((wcu = towupper(wc)) == wc) {
+ /* already uppercase, just draw the character */
+ setfont(ff->font, ff->size);
+ width += font->letterSpacing;
+ width += (int)getwidth(text + curr, next - curr);
+ } else {
+ /* make utf8 string for converted char */
+ nb = utf8encode(wcu, chbuf);
+ setfont(ff->font, sc_fontsize);
+ width += font->letterSpacing;
+ width += (int)getwidth(chbuf, nb);
+ }
+ }
+ } else {
+ setfont (ff->font, ff->size);
+ width = (int) getwidth (text, len);
+
+ if (font->letterSpacing) {
+ int curr = 0, next = 0;
+
+ while (next < len) {
+ next = nextGlyph(text, curr);
+ width += font->letterSpacing;
+ curr = next;
+ }
}
}
+
return width;
}
diff --git a/dw/fltkui.cc b/dw/fltkui.cc
index c1bfd873..07874f2c 100644
--- a/dw/fltkui.cc
+++ b/dw/fltkui.cc
@@ -989,7 +989,7 @@ template <class I> void FltkSelectionResource<I>::addItem (const char *str,
itemWidget->set_selected();
if (setSelectedItems ()) {
// Handle multiple item selection.
- int pos[widgetStack->stack->size ()];
+ int *pos = new int[widgetStack->stack->size ()];
int i;
Iterator <TypedPointer < ::fltk::Menu> > it;
for (it = widgetStack->stack->iterator (),
@@ -1000,6 +1000,7 @@ template <class I> void FltkSelectionResource<I>::addItem (const char *str,
pos[i] = p->getTypedValue()->children () - 1;
}
widgetStack->widget->set_item (pos, widgetStack->stack->size ());
+ delete [] pos;
}
}
}
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc
index 7d519f05..3fb43cb1 100644
--- a/dw/fltkviewbase.cc
+++ b/dw/fltkviewbase.cc
@@ -27,8 +27,11 @@
#include <fltk/events.h>
#include <fltk/Cursor.h>
#include <fltk/run.h>
+#include <fltk/utf.h>
#include <stdio.h>
+#include <wchar.h>
+#include <wctype.h>
#include "../lout/msg.h"
using namespace fltk;
@@ -483,20 +486,45 @@ void FltkWidgetView::drawText (core::style::Font *font,
setfont(ff->font, ff->size);
setcolor(((FltkColor*)color)->colors[shading]);
- if (!font->letterSpacing) {
+ if (!font->letterSpacing && !font->fontVariant) {
drawtext(text, len,
translateCanvasXToViewX (x), translateCanvasYToViewY (y));
} else {
/* Nonzero letter spacing adjustment, draw each glyph individually */
int viewX = translateCanvasXToViewX (x),
viewY = translateCanvasYToViewY (y);
- int curr = 0, next = 0;
-
- while (next < len) {
- next = theLayout->nextGlyph(text, curr);
- drawtext(text + curr, next - curr, viewX, viewY);
- viewX += font->letterSpacing + (int)getwidth(text + curr,next - curr);
- curr = next;
+ int curr = 0, next = 0, nb;
+ char chbuf[4];
+ wchar_t wc, wcu;
+
+ if (font->fontVariant == 1) {
+ int sc_fontsize = lout::misc::roundInt(ff->size * 0.78);
+ for (curr = 0; next < len; curr = next) {
+ next = theLayout->nextGlyph(text, curr);
+ wc = utf8decode(text + curr, text + next, &nb);
+ if ((wcu = towupper(wc)) == wc) {
+ /* already uppercase, just draw the character */
+ setfont(ff->font, ff->size);
+ drawtext(text + curr, next - curr, viewX, viewY);
+ viewX += font->letterSpacing;
+ viewX += (int)getwidth(text + curr, next - curr);
+ } else {
+ /* make utf8 string for converted char */
+ nb = utf8encode(wcu, chbuf);
+ setfont(ff->font, sc_fontsize);
+ drawtext(chbuf, nb, viewX, viewY);
+ viewX += font->letterSpacing;
+ viewX += (int)getwidth(chbuf, nb);
+ }
+ }
+ } else {
+ while (next < len) {
+ next = theLayout->nextGlyph(text, curr);
+ drawtext(text + curr, next - curr, viewX, viewY);
+ viewX += font->letterSpacing +
+ (int)getwidth(text + curr,next - curr);
+ curr = next;
+ }
}
}
}
diff --git a/dw/style.cc b/dw/style.cc
index cc58ce28..30597af2 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -269,6 +269,7 @@ bool FontAttrs::equals(object::Object *other)
weight == otherAttrs->weight &&
style == otherAttrs->style &&
letterSpacing == otherAttrs->letterSpacing &&
+ fontVariant == otherAttrs->fontVariant &&
strcmp (name, otherAttrs->name) == 0);
}
@@ -279,6 +280,7 @@ int FontAttrs::hashValue()
h = (h << 5) - h + weight;
h = (h << 5) - h + style;
h = (h << 5) - h + letterSpacing;
+ h = (h << 5) - h + fontVariant;
return h;
}
@@ -294,6 +296,7 @@ void Font::copyAttrs (FontAttrs *attrs)
weight = attrs->weight;
style = attrs->style;
letterSpacing = attrs->letterSpacing;
+ fontVariant = attrs->fontVariant;
}
Font *Font::create0 (Layout *layout, FontAttrs *attrs,
diff --git a/dw/style.hh b/dw/style.hh
index 04a5e22e..33d42c29 100644
--- a/dw/style.hh
+++ b/dw/style.hh
@@ -64,7 +64,7 @@ namespace core {
* attribute, which is supported by dillo, will refer to an attribute in
* dw::core::style::Style. For this reason, the attributes in
* dw::core::style::Style get the names from the CSS attributes, with
- * "camelCase" instead of hythens (e.g. "background-color" becomes
+ * "camelCase" instead of hyphens (e.g. "background-color" becomes
* "backgroundColor").
*
* However, dw::core::style::Style will be extended by some more
@@ -293,6 +293,11 @@ enum FontStyle {
FONT_STYLE_OBLIQUE
};
+enum FontVariant {
+ FONT_VARIANT_NORMAL,
+ FONT_VARIANT_SMALL_CAPS
+};
+
enum TextDecoration {
TEXT_DECORATION_NONE = 0,
TEXT_DECORATION_UNDERLINE = 1 << 0,
@@ -558,6 +563,7 @@ public:
int size;
int weight;
int letterSpacing;
+ FontVariant fontVariant;
FontStyle style;
bool equals(lout::object::Object *other);
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 4c02287c..81fbcb69 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -1218,20 +1218,20 @@ void Textblock::decorateText(core::View *view, core::style::Style *style,
core::style::Color::Shading shading,
int x, int yBase, int width)
{
- int y;
+ int y, height;
+ height = 1 + style->font->xHeight / 12;
if (style->textDecoration & core::style::TEXT_DECORATION_UNDERLINE) {
- y = yBase + 1;
- view->drawLine (style->color, shading, x, y, x + width - 1, y);
+ y = yBase + style->font->descent / 3;
+ view->drawRectangle (style->color, shading, true, x, y, width, height);
}
if (style->textDecoration & core::style::TEXT_DECORATION_OVERLINE) {
- y = yBase - style->font->ascent + 1;
- view->drawLine (style->color, shading, x, y, x + width - 1, y);
+ y = yBase - style->font->ascent;
+ view->drawRectangle (style->color, shading, true, x, y, width, height);
}
if (style->textDecoration & core::style::TEXT_DECORATION_LINE_THROUGH) {
- int height = 1 + style->font->xHeight / 10;
-
- y = yBase + (style->font->descent - style->font->ascent) / 2;
+ y = yBase + (style->font->descent - style->font->ascent) / 2 +
+ style->font->descent / 4;
view->drawRectangle (style->color, shading, true, x, y, width, height);
}
}
diff --git a/dw/ui.cc b/dw/ui.cc
index 058dfde8..5d5d2bf6 100644
--- a/dw/ui.cc
+++ b/dw/ui.cc
@@ -280,7 +280,7 @@ ComplexButtonResource::ComplexButtonResource ()
void ComplexButtonResource::init (Widget *widget)
{
- this->widget = widget;
+ this->childWidget = widget;
layout = new Layout (createPlatform ());
setLayout (layout);
@@ -292,7 +292,7 @@ void ComplexButtonResource::setEmbed (Embed *embed)
{
ButtonResource::setEmbed (embed);
- if (widget->usesHints ())
+ if (childWidget->usesHints ())
embed->setUsesHints ();
}
@@ -304,7 +304,7 @@ ComplexButtonResource::~ComplexButtonResource ()
void ComplexButtonResource::sizeRequest (Requisition *requisition)
{
Requisition widgetRequisition;
- widget->sizeRequest (&widgetRequisition);
+ childWidget->sizeRequest (&widgetRequisition);
requisition->width = widgetRequisition.width + 2 * reliefXThickness ();
requisition->ascent = widgetRequisition.ascent + reliefYThickness ();
requisition->descent = widgetRequisition.descent + reliefYThickness ();
@@ -313,7 +313,7 @@ void ComplexButtonResource::sizeRequest (Requisition *requisition)
void ComplexButtonResource::getExtremes (Extremes *extremes)
{
Extremes widgetExtremes;
- widget->getExtremes (&widgetExtremes);
+ childWidget->getExtremes (&widgetExtremes);
extremes->minWidth = widgetExtremes.minWidth + 2 * reliefXThickness ();
extremes->maxWidth = widgetExtremes.maxWidth + 2 * reliefXThickness ();
}
@@ -324,17 +324,17 @@ void ComplexButtonResource::sizeAllocate (Allocation *allocation)
void ComplexButtonResource::setWidth (int width)
{
- widget->setWidth (width - 2 * reliefXThickness ());
+ childWidget->setWidth (width - 2 * reliefXThickness ());
}
void ComplexButtonResource::setAscent (int ascent)
{
- widget->setAscent (ascent - reliefYThickness ());
+ childWidget->setAscent (ascent - reliefYThickness ());
}
void ComplexButtonResource::setDescent (int descent)
{
- widget->setDescent (descent - reliefYThickness ());
+ childWidget->setDescent (descent - reliefYThickness ());
}
Iterator *ComplexButtonResource::iterator (Content::Type mask, bool atEnd)
diff --git a/dw/ui.hh b/dw/ui.hh
index 02aab093..b0a22cbf 100644
--- a/dw/ui.hh
+++ b/dw/ui.hh
@@ -382,7 +382,7 @@ private:
friend class LayoutReceiver;
LayoutReceiver layoutReceiver;
- Widget *widget;
+ Widget *childWidget;
protected:
Layout *layout;