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 GtkWidget *nhspinb;
static GtkWidget *nvspinb;
static GtkWidget *textstr;
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
{
@ -208,6 +209,11 @@ int main(void)
gtk_grid_attach(GTK_GRID(grid), nvspinb,
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));
gtk_container_add(GTK_CONTAINER(scroller), area);

View File

@ -63,7 +63,6 @@ enum uiDrawLineJoin {
enum uiDrawFillMode {
uiDrawFillModeWinding,
// TODO rename to EvenOdd?
uiDrawFillModeAlternate,
};
@ -90,35 +89,76 @@ void uiDrawCloseFigure(uiDrawContext *);
void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *);
void uiDrawFill(uiDrawContext *, uiDrawFillMode);
// path functions
// cairo gdi core graphics
// move_to MoveToEx MoveToPoint
// line_to LineTo AddLineToPoint
// 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
// TODO primitives:
// - rounded rectangles
// - elliptical arcs
// - quadratic bezier curves
// on sources:
// cairo:
// - RGB
// - RGBA
// - images
// - linear gradients, RGB or RGBA
// - rounded gradients, RGB or RGBA
// gdi:
// - RGB
// - hatches
// - images
// we can create a linear gradient image, but RGB only, and of finite size
// core graphics:
// - arbitrary patterns
// - solid colors, arbitrary spaces
// - shadows
typedef struct uiDrawFont uiDrawFont;
typedef struct uiDrawFontSpec uiDrawFontSpec;
typedef struct uiDrawTextBlockParams uiDrawTextBlockParams;
typedef struct uiDrawFontMetrics uiDrawFontMetrics;
typedef enum uiDrawTextWeight uiDrawTextWeight;
typedef enum uiDrawTextAlign uiDrawTextAlign;
enum uiDrawTextWeight {
uiDrawTextWeightThin,
uiDrawTextWeightExtraLight,
uiDrawTextWeightLight,
uiDrawTextWeightNormal,
uiDrawTextWeightMedium,
uiDrawTextWeightSemiBold,
uiDrawTextWeightBold,
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;

View File

@ -63,7 +63,6 @@ enum uiDrawLineJoin {
enum uiDrawFillMode {
uiDrawFillModeWinding,
// TODO rename to EvenOdd?
uiDrawFillModeAlternate,
};
@ -90,35 +89,76 @@ void uiDrawCloseFigure(uiDrawContext *);
void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *);
void uiDrawFill(uiDrawContext *, uiDrawFillMode);
// path functions
// cairo gdi core graphics
// move_to MoveToEx MoveToPoint
// line_to LineTo AddLineToPoint
// 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
// TODO primitives:
// - rounded rectangles
// - elliptical arcs
// - quadratic bezier curves
// on sources:
// cairo:
// - RGB
// - RGBA
// - images
// - linear gradients, RGB or RGBA
// - rounded gradients, RGB or RGBA
// gdi:
// - RGB
// - hatches
// - images
// we can create a linear gradient image, but RGB only, and of finite size
// core graphics:
// - arbitrary patterns
// - solid colors, arbitrary spaces
// - shadows
typedef struct uiDrawFont uiDrawFont;
typedef struct uiDrawFontSpec uiDrawFontSpec;
typedef struct uiDrawTextBlockParams uiDrawTextBlockParams;
typedef struct uiDrawFontMetrics uiDrawFontMetrics;
typedef enum uiDrawTextWeight uiDrawTextWeight;
typedef enum uiDrawTextAlign uiDrawTextAlign;
enum uiDrawTextWeight {
uiDrawTextWeightThin,
uiDrawTextWeightExtraLight,
uiDrawTextWeightLight,
uiDrawTextWeightNormal,
uiDrawTextWeightMedium,
uiDrawTextWeightSemiBold,
uiDrawTextWeightBold,
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;

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 {
uiDrawFillModeWinding,
// TODO rename to EvenOdd?
uiDrawFillModeAlternate,
};
@ -90,35 +89,76 @@ void uiDrawCloseFigure(uiDrawContext *);
void uiDrawStroke(uiDrawContext *, uiDrawStrokeParams *);
void uiDrawFill(uiDrawContext *, uiDrawFillMode);
// path functions
// cairo gdi core graphics
// move_to MoveToEx MoveToPoint
// line_to LineTo AddLineToPoint
// 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
// TODO primitives:
// - rounded rectangles
// - elliptical arcs
// - quadratic bezier curves
// on sources:
// cairo:
// - RGB
// - RGBA
// - images
// - linear gradients, RGB or RGBA
// - rounded gradients, RGB or RGBA
// gdi:
// - RGB
// - hatches
// - images
// we can create a linear gradient image, but RGB only, and of finite size
// core graphics:
// - arbitrary patterns
// - solid colors, arbitrary spaces
// - shadows
typedef struct uiDrawFont uiDrawFont;
typedef struct uiDrawFontSpec uiDrawFontSpec;
typedef struct uiDrawTextBlockParams uiDrawTextBlockParams;
typedef struct uiDrawFontMetrics uiDrawFontMetrics;
typedef enum uiDrawTextWeight uiDrawTextWeight;
typedef enum uiDrawTextAlign uiDrawTextAlign;
enum uiDrawTextWeight {
uiDrawTextWeightThin,
uiDrawTextWeightExtraLight,
uiDrawTextWeightLight,
uiDrawTextWeightNormal,
uiDrawTextWeightMedium,
uiDrawTextWeightSemiBold,
uiDrawTextWeightBold,
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;