git-svn-id: svn://ultimatepp.org/upp/trunk@5610 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-12-02 10:39:27 +00:00
parent 6ca4a81272
commit 9fb98817a0
3 changed files with 87 additions and 55 deletions

View file

@ -9,7 +9,7 @@ void GtkDraw::SetColor(Color c)
dword GtkDraw::GetInfo() const
{
return 0;
return DRAWTEXTLINES;
}
Point GtkDraw::GetOffset() const
@ -130,6 +130,11 @@ void GtkDraw::SysDrawImageOp(int x, int y, const Image& img, Color color)
void GtkDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color)
{
SetColor(color);
cairo_move_to(cr, x1, y1);
cairo_line_to(cr, x2, y2);
cairo_set_line_width (cr, width);
cairo_stroke(cr);
}
void GtkDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor)
@ -150,27 +155,49 @@ void GtkDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor)
namespace Upp {
FcPattern *CreateFcPattern(Font font);
FT_Face FTFace(Font fnt, String *rpath = NULL);
};
void GtkDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx)
{
FcPattern *p = CreateFcPattern(font);
cairo_font_face_t *face = cairo_ft_font_face_create_for_pattern(p);
cairo_font_face_t *font_face = cairo_ft_font_face_create_for_pattern(p);
FcPatternDestroy(p);
int xpos = 0;
Buffer<cairo_glyph_t> gs(n);
for(int i = 0; i < n; i++) {
cairo_glyph_t& g = gs[i];
g.index = GetGlyphInfo(font, text[i]).glyphi;
g.x = x;
g.index = FT_Get_Char_Index(FTFace(font), text[i]);
g.x = x + xpos;
g.y = y + font.GetAscent();
x += dx ? dx[i] : font[text[i]];
xpos += dx ? dx[i] : font[text[i]];
}
#if 1
cairo_matrix_t font_matrix[1], ctm[1];
cairo_matrix_init_identity(ctm);
cairo_matrix_init_scale(font_matrix, font.GetHeight(), font.GetHeight());
if(angle)
cairo_matrix_rotate(font_matrix, -angle * M_2PI / 3600);
cairo_font_options_t *opt = cairo_font_options_create();
cairo_scaled_font_t *sf = cairo_scaled_font_create(font_face, font_matrix, ctm, opt);
SetColor(ink);
cairo_set_scaled_font(cr, sf);
cairo_show_glyphs(cr, gs, n);
cairo_font_options_destroy(opt);
cairo_scaled_font_destroy(sf);
#else
cairo_set_font_face(cr, face);
cairo_set_font_size(cr, font.GetHeight());
SetColor(ink);
DDUMP(y + font.GetAscent());
cairo_show_glyphs(cr, gs, n);
cairo_font_face_destroy(face);
#endif
cairo_font_face_destroy(font_face);
}

View file

@ -8,42 +8,53 @@
#define IMAGEFILE <GtkApp/Test.iml>
#include <Draw/iml_source.h>
static gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
void TestDraw(Draw& w)
{
GtkDraw w;
w.cr = gdk_cairo_create(widget->window);
w.DrawRect(0, 0, 100, 100, Yellow());
w.DrawLine(10, 40, 400, 20, 3, Blue());
w.DrawImage(0, 0, TestImg::Test());
w.Clipoff(50, 50, 30, 30);
w.DrawImage(0, 0, TestImg::Test());
w.End();
w.DrawImage(50, 50 + 32, TestImg::Test(), Rect(24, 24, 10, 10));
w.DrawImage(50, 50 + 32, TestImg::Test(), RectC(24, 24, 10, 10));
w.DrawImage(150, 50, TestImg::Test(), Red());
w.DrawImage(150, 50 + 32, TestImg::Test(), Rect(24, 24, 10, 10), Red());
w.DrawImage(150, 50 + 32, TestImg::Test(), RectC(24, 24, 10, 10), Red());
// w.DrawText(20, 20, "Hello GTK!", Roman(50));
w.Offset(150, 50);
const char *text = "Programming is fun";
Font fnt(Roman(60));
FontInfo fi = fnt.Info();
int x = 0;
Vector<int> dx;
for(const char *s = text; *s; s++) {
int width = fi[*s];
w.DrawRect(x, 0, width - 1, fi.GetAscent(), Color(255, 255, 200));
w.DrawRect(x, fi.GetAscent(), width - 1, fi.GetDescent(), Color(255, 200, 255));
w.DrawRect(x + width - 1, 0, 1, fi.GetHeight(), Black());
dx.Add(width + 4);
x += width;
}
w.DrawRect(0, 0, 4, 4, Black());
w.DrawText(0, 0, text, fnt);
w.DrawText(0, 70, text, fnt, Blue(), dx.GetCount(), dx.Begin());
w.Offset(150, 50);
const char *text = "Programming is fun";
Font fnt(Roman(60));
FontInfo fi = fnt.Info();
int x = 0;
Vector<int> dx;
for(const char *s = text; *s; s++) {
int width = fi[*s];
w.DrawRect(x, 0, width - 1, fi.GetAscent(), Color(255, 255, 200));
w.DrawRect(x, fi.GetAscent(), width - 1, fi.GetDescent(), Color(255, 200, 255));
w.DrawRect(x + width - 1, 0, 1, fi.GetHeight(), Black());
dx.Add(width + 4);
x += width;
}
w.DrawRect(0, 0, 4, 4, Black());
w.DrawText(0, 0, text, fnt);
w.DrawText(0, 70, text, fnt, Blue(), dx.GetCount(), dx.Begin());
w.DrawText(50, 400, 200, "Angled text", Arial(100).Underline(), Black());
}
static gboolean on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
GtkDraw w;
w.cr = gdk_cairo_create(widget->window);
TestDraw(w);
cairo_destroy(w.cr);

View file

@ -13,33 +13,27 @@ CONSOLE_APP_MAIN
pdf.DrawText(100, 100, "Ahoj", Courier(100).Bold(), Black);
#else
int cy = 0;
// for(int face = Font::SERIF; face < min(99999, Font::GetFaceCount()); face++)
int face = 6;
for(int underline = 0; underline < 2; underline++)
for(int italic = 0; italic < 2; italic++)
for(int bold = 0; bold < 2; bold++) {
String h;
if(bold)
h << " bold";
if(italic)
h << " italic";
if(underline)
h << " underline";
Font fnt(face, 50);
fnt.Bold(bold).Italic(italic).Underline(underline);
Cout() << fnt << "\n";
LOG(face << ' ' << fnt << ", TTF: " << fnt.IsTrueType());
if(1 || fnt.IsTrueType()) {
pdf.DrawText(100, cy, fnt.GetFaceName() + h, fnt, Black);
// pdf.DrawText(2000, cy, 200, fnt.GetFaceName() + h, fnt, Black);
cy += fnt.GetLineHeight();
if(cy > 6000) {
pdf.EndPage();
pdf.StartPage();
cy = 0;
for(int face = Font::SERIF; face < min(9, Font::GetFaceCount()); face++)
// int face = 6;
for(int strikeout = 0; strikeout < 2; strikeout++)
for(int underline = 0; underline < 2; underline++)
for(int italic = 0; italic < 2; italic++)
for(int bold = 0; bold < 2; bold++) {
Font fnt(face, 100);
fnt.Bold(bold).Italic(italic).Underline(underline).Strikeout(strikeout);
Cout() << fnt << "\n";
LOG(face << ' ' << fnt << ", TTF: " << fnt.IsTrueType());
if(1 || fnt.IsTrueType()) {
pdf.DrawText(100, cy, AsString(fnt), fnt, Black);
pdf.DrawText(2000, cy, 200, AsString(fnt), fnt, Black);
cy += fnt.GetLineHeight();
if(cy > 6000) {
pdf.EndPage();
pdf.StartPage();
cy = 0;
}
}
}
}
#endif
SaveFile(GetHomeDirFile("pdf.pdf"), pdf.Finish());
}