More uiArea API work. Text rendering functions started. I'll start with Windows because it'll require Uniscribe.

This commit is contained in:
Pietro Gagliardi 2015-09-14 20:02:52 -04:00
parent 1197cf4ada
commit 882dec1ad4
5 changed files with 222 additions and 87 deletions

View File

@ -13,6 +13,7 @@ static GtkWidget *area;
static struct handler h; static struct handler h;
static GtkWidget *nhspinb; static GtkWidget *nhspinb;
static GtkWidget *nvspinb; static GtkWidget *nvspinb;
static GtkWidget *textstr;
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
{ {
@ -208,6 +209,11 @@ int main(void)
gtk_grid_attach(GTK_GRID(grid), nvspinb, gtk_grid_attach(GTK_GRID(grid), nvspinb,
1, 1, 1, 1); 1, 1, 1, 1);
textstr = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(textstr), "ベア・ナックルII 死闘への鎮魂歌");
gtk_grid_attach(GTK_GRID(grid), textstr,
2, 0, 1, 1);
area = newArea((uiAreaHandler *) (&h)); area = newArea((uiAreaHandler *) (&h));
gtk_container_add(GTK_CONTAINER(scroller), area); gtk_container_add(GTK_CONTAINER(scroller), area);

View File

@ -63,7 +63,6 @@ enum uiDrawLineJoin {
enum uiDrawFillMode { enum uiDrawFillMode {
uiDrawFillModeWinding, uiDrawFillModeWinding,
// TODO rename to EvenOdd?
uiDrawFillModeAlternate, uiDrawFillModeAlternate,
}; };
@ -90,35 +89,76 @@ void uiDrawCloseFigure(uiDrawContext *);
void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *); void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *);
void uiDrawFill(uiDrawContext *, uiDrawFillMode); void uiDrawFill(uiDrawContext *, uiDrawFillMode);
// path functions // TODO primitives:
// cairo gdi core graphics // - rounded rectangles
// move_to MoveToEx MoveToPoint // - elliptical arcs
// line_to LineTo AddLineToPoint // - quadratic bezier curves
// arc Arc/ArcTo/AngleArc/Pie AddArc/AddArcToPoint/AddEllipseInRect
// arc_negative Arc/ArcTo/AngleArc/Pie AddArc/AddArcToPoint
// curve_to PolyBezier/PolyBezierTo AddCurveToPoint
// rectangle Rectangle AddRect
// [arc functions?] Chord [arc functions?]
// [combination] RoundRect [same way as cairo?]
// [TODO pango] TextOut/ExtTextOut [TODO core text]
// [TODO] [TODO] AddQuadCurveToPoint
// on sources: typedef struct uiDrawFont uiDrawFont;
// cairo: typedef struct uiDrawFontSpec uiDrawFontSpec;
// - RGB typedef struct uiDrawTextBlockParams uiDrawTextBlockParams;
// - RGBA typedef struct uiDrawFontMetrics uiDrawFontMetrics;
// - images typedef enum uiDrawTextWeight uiDrawTextWeight;
// - linear gradients, RGB or RGBA typedef enum uiDrawTextAlign uiDrawTextAlign;
// - rounded gradients, RGB or RGBA
// gdi: enum uiDrawTextWeight {
// - RGB uiDrawTextWeightThin,
// - hatches uiDrawTextWeightExtraLight,
// - images uiDrawTextWeightLight,
// we can create a linear gradient image, but RGB only, and of finite size uiDrawTextWeightNormal,
// core graphics: uiDrawTextWeightMedium,
// - arbitrary patterns uiDrawTextWeightSemiBold,
// - solid colors, arbitrary spaces uiDrawTextWeightBold,
// - shadows uiDrawTextWeightExtraBold,
uiDrawTextWeightHeavy,
};
struct uiDrawFontSpec {
const char *Family;
uintmax_t PointSize;
uiDrawTextWeight Weight;
int Italic; // always prefers true italics over obliques whenever possible
int Vertical;
};
enum uiDrawTextAlign {
uiDrawTextAlignLeft,
uiDrawTextAlignCenter,
uiDrawTextAlignRight,
};
struct uiDrawTextBlockParams {
intmax_t Width;
intmax_t FirstLineIndent;
intmax_t LineSpacing;
uiDrawTextAlign Align;
int Justify;
};
struct uiDrawFontMetrics {
// TODO
// metrics on Windows are per-device; other platforms not?
};
#define uiDrawTextPixelSizeToPointSize(pix, dpiY) \
((uintmax_t) ((((double) (pix)) * 72.0) / ((double) (dpiY))))
#define uiDrawTextPointSizeToPixelSize(pt, dpiY) \
((uintmax_t) (((double) (pt)) * (((double) (dpiY)) / 72.0)))
uiDrawFont *uiDrawPrepareFont(uiDrawFontSpec *);
void uiDrawFreeFont(uiDrawFont *);
void uiDrawText(uiDrawContext *, const char *, uiDrawFont *, intmax_t, intmax_t);
void uiDrawTextBlock(uiDrawContext *, const char *, uiDrawFont *, intmax_t, intmax_t, uiDrawTextBlockParams *);
void uiDrawTextExtents(uiDrawContext *, const char *, uiDrawFont *, intmax_t *, intmax_t *);
intmax_t uiDrawTextExtentsBlockHeight(uiDrawContext *, const char *, uiDrawFont *, uiDrawTextBlockParams *);
//TODOvoid uiDrawContextFontMetrics(uiDrawContext *, uiDrawFont *, uiDrawFontMetrics *);
// TODO draw text, single line, control font
// TODO draw text, wrapped to width, control font
// TODO get text extents, single line, control font
// TODO get text height for width, control font
// TODO get font metrics, control font
typedef enum uiModifiers uiModifiers; typedef enum uiModifiers uiModifiers;

View File

@ -63,7 +63,6 @@ enum uiDrawLineJoin {
enum uiDrawFillMode { enum uiDrawFillMode {
uiDrawFillModeWinding, uiDrawFillModeWinding,
// TODO rename to EvenOdd?
uiDrawFillModeAlternate, uiDrawFillModeAlternate,
}; };
@ -90,35 +89,76 @@ void uiDrawCloseFigure(uiDrawContext *);
void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *); void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *);
void uiDrawFill(uiDrawContext *, uiDrawFillMode); void uiDrawFill(uiDrawContext *, uiDrawFillMode);
// path functions // TODO primitives:
// cairo gdi core graphics // - rounded rectangles
// move_to MoveToEx MoveToPoint // - elliptical arcs
// line_to LineTo AddLineToPoint // - quadratic bezier curves
// arc Arc/ArcTo/AngleArc/Pie AddArc/AddArcToPoint/AddEllipseInRect
// arc_negative Arc/ArcTo/AngleArc/Pie AddArc/AddArcToPoint
// curve_to PolyBezier/PolyBezierTo AddCurveToPoint
// rectangle Rectangle AddRect
// [arc functions?] Chord [arc functions?]
// [combination] RoundRect [same way as cairo?]
// [TODO pango] TextOut/ExtTextOut [TODO core text]
// [TODO] [TODO] AddQuadCurveToPoint
// on sources: typedef struct uiDrawFont uiDrawFont;
// cairo: typedef struct uiDrawFontSpec uiDrawFontSpec;
// - RGB typedef struct uiDrawTextBlockParams uiDrawTextBlockParams;
// - RGBA typedef struct uiDrawFontMetrics uiDrawFontMetrics;
// - images typedef enum uiDrawTextWeight uiDrawTextWeight;
// - linear gradients, RGB or RGBA typedef enum uiDrawTextAlign uiDrawTextAlign;
// - rounded gradients, RGB or RGBA
// gdi: enum uiDrawTextWeight {
// - RGB uiDrawTextWeightThin,
// - hatches uiDrawTextWeightExtraLight,
// - images uiDrawTextWeightLight,
// we can create a linear gradient image, but RGB only, and of finite size uiDrawTextWeightNormal,
// core graphics: uiDrawTextWeightMedium,
// - arbitrary patterns uiDrawTextWeightSemiBold,
// - solid colors, arbitrary spaces uiDrawTextWeightBold,
// - shadows uiDrawTextWeightExtraBold,
uiDrawTextWeightHeavy,
};
struct uiDrawFontSpec {
const char *Family;
uintmax_t PointSize;
uiDrawTextWeight Weight;
int Italic; // always prefers true italics over obliques whenever possible
int Vertical;
};
enum uiDrawTextAlign {
uiDrawTextAlignLeft,
uiDrawTextAlignCenter,
uiDrawTextAlignRight,
};
struct uiDrawTextBlockParams {
intmax_t Width;
intmax_t FirstLineIndent;
intmax_t LineSpacing;
uiDrawTextAlign Align;
int Justify;
};
struct uiDrawFontMetrics {
// TODO
// metrics on Windows are per-device; other platforms not?
};
#define uiDrawTextPixelSizeToPointSize(pix, dpiY) \
((uintmax_t) ((((double) (pix)) * 72.0) / ((double) (dpiY))))
#define uiDrawTextPointSizeToPixelSize(pt, dpiY) \
((uintmax_t) (((double) (pt)) * (((double) (dpiY)) / 72.0)))
uiDrawFont *uiDrawPrepareFont(uiDrawFontSpec *);
void uiDrawFreeFont(uiDrawFont *);
void uiDrawText(uiDrawContext *, const char *, uiDrawFont *, intmax_t, intmax_t);
void uiDrawTextBlock(uiDrawContext *, const char *, uiDrawFont *, intmax_t, intmax_t, uiDrawTextBlockParams *);
void uiDrawTextExtents(uiDrawContext *, const char *, uiDrawFont *, intmax_t *, intmax_t *);
intmax_t uiDrawTextExtentsBlockHeight(uiDrawContext *, const char *, uiDrawFont *, uiDrawTextBlockParams *);
//TODOvoid uiDrawContextFontMetrics(uiDrawContext *, uiDrawFont *, uiDrawFontMetrics *);
// TODO draw text, single line, control font
// TODO draw text, wrapped to width, control font
// TODO get text extents, single line, control font
// TODO get text height for width, control font
// TODO get font metrics, control font
typedef enum uiModifiers uiModifiers; typedef enum uiModifiers uiModifiers;

9
osxweights Normal file
View File

@ -0,0 +1,9 @@
NSFontWeightUltraLight -0.800000
NSFontWeightThin -0.600000
NSFontWeightLight -0.400000
NSFontWeightRegular 0.000000
NSFontWeightMedium 0.230000
NSFontWeightSemibold 0.300000
NSFontWeightBold 0.400000
NSFontWeightHeavy 0.560000
NSFontWeightBlack 0.620000

View File

@ -63,7 +63,6 @@ enum uiDrawLineJoin {
enum uiDrawFillMode { enum uiDrawFillMode {
uiDrawFillModeWinding, uiDrawFillModeWinding,
// TODO rename to EvenOdd?
uiDrawFillModeAlternate, uiDrawFillModeAlternate,
}; };
@ -90,35 +89,76 @@ void uiDrawCloseFigure(uiDrawContext *);
void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *); void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *);
void uiDrawFill(uiDrawContext *, uiDrawFillMode); void uiDrawFill(uiDrawContext *, uiDrawFillMode);
// path functions // TODO primitives:
// cairo gdi core graphics // - rounded rectangles
// move_to MoveToEx MoveToPoint // - elliptical arcs
// line_to LineTo AddLineToPoint // - quadratic bezier curves
// arc Arc/ArcTo/AngleArc/Pie AddArc/AddArcToPoint/AddEllipseInRect
// arc_negative Arc/ArcTo/AngleArc/Pie AddArc/AddArcToPoint
// curve_to PolyBezier/PolyBezierTo AddCurveToPoint
// rectangle Rectangle AddRect
// [arc functions?] Chord [arc functions?]
// [combination] RoundRect [same way as cairo?]
// [TODO pango] TextOut/ExtTextOut [TODO core text]
// [TODO] [TODO] AddQuadCurveToPoint
// on sources: typedef struct uiDrawFont uiDrawFont;
// cairo: typedef struct uiDrawFontSpec uiDrawFontSpec;
// - RGB typedef struct uiDrawTextBlockParams uiDrawTextBlockParams;
// - RGBA typedef struct uiDrawFontMetrics uiDrawFontMetrics;
// - images typedef enum uiDrawTextWeight uiDrawTextWeight;
// - linear gradients, RGB or RGBA typedef enum uiDrawTextAlign uiDrawTextAlign;
// - rounded gradients, RGB or RGBA
// gdi: enum uiDrawTextWeight {
// - RGB uiDrawTextWeightThin,
// - hatches uiDrawTextWeightExtraLight,
// - images uiDrawTextWeightLight,
// we can create a linear gradient image, but RGB only, and of finite size uiDrawTextWeightNormal,
// core graphics: uiDrawTextWeightMedium,
// - arbitrary patterns uiDrawTextWeightSemiBold,
// - solid colors, arbitrary spaces uiDrawTextWeightBold,
// - shadows uiDrawTextWeightExtraBold,
uiDrawTextWeightHeavy,
};
struct uiDrawFontSpec {
const char *Family;
uintmax_t PointSize;
uiDrawTextWeight Weight;
int Italic; // always prefers true italics over obliques whenever possible
int Vertical;
};
enum uiDrawTextAlign {
uiDrawTextAlignLeft,
uiDrawTextAlignCenter,
uiDrawTextAlignRight,
};
struct uiDrawTextBlockParams {
intmax_t Width;
intmax_t FirstLineIndent;
intmax_t LineSpacing;
uiDrawTextAlign Align;
int Justify;
};
struct uiDrawFontMetrics {
// TODO
// metrics on Windows are per-device; other platforms not?
};
#define uiDrawTextPixelSizeToPointSize(pix, dpiY) \
((uintmax_t) ((((double) (pix)) * 72.0) / ((double) (dpiY))))
#define uiDrawTextPointSizeToPixelSize(pt, dpiY) \
((uintmax_t) (((double) (pt)) * (((double) (dpiY)) / 72.0)))
uiDrawFont *uiDrawPrepareFont(uiDrawFontSpec *);
void uiDrawFreeFont(uiDrawFont *);
void uiDrawText(uiDrawContext *, const char *, uiDrawFont *, intmax_t, intmax_t);
void uiDrawTextBlock(uiDrawContext *, const char *, uiDrawFont *, intmax_t, intmax_t, uiDrawTextBlockParams *);
void uiDrawTextExtents(uiDrawContext *, const char *, uiDrawFont *, intmax_t *, intmax_t *);
intmax_t uiDrawTextExtentsBlockHeight(uiDrawContext *, const char *, uiDrawFont *, uiDrawTextBlockParams *);
//TODOvoid uiDrawContextFontMetrics(uiDrawContext *, uiDrawFont *, uiDrawFontMetrics *);
// TODO draw text, single line, control font
// TODO draw text, wrapped to width, control font
// TODO get text extents, single line, control font
// TODO get text height for width, control font
// TODO get font metrics, control font
typedef enum uiModifiers uiModifiers; typedef enum uiModifiers uiModifiers;