Draw, CtrlCore: Major refactor of Draw

git-svn-id: svn://ultimatepp.org/upp/trunk@5545 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-11-11 12:33:47 +00:00
parent fa5f9ec55e
commit bd87a04fda
37 changed files with 2704 additions and 2655 deletions

View file

@ -6,7 +6,6 @@ NAMESPACE_UPP
#define LLOG(x) // LOG(x)
#define PDF_COMPRESS
#define USE_TTF
static const char ICC_ColorSpaceInfo[] =
"H\211\234\226yTSw\026\307\177o\311\236\220\225\260\303c\r[\200\260\006\2205la\221"
@ -344,10 +343,6 @@ void PdfDraw::PutFontHeight(int fi, double ht)
page << "/F" << ((fontid = fi) + 1) << ' ' << Pt(textht = ht) << " Tf\n";
}
#ifdef PLATFORM_WIN32
HFONT GetWin32Font(Font fnt, int angle);
HDC Win32_IC();
#endif
PdfDraw::OutlineInfo PdfDraw::GetOutlineInfo(Font fnt)
{
@ -358,44 +353,11 @@ PdfDraw::OutlineInfo PdfDraw::GetOutlineInfo(Font fnt)
OutlineInfo of;
of.sitalic = of.ttf = false;
#ifdef USE_TTF
#ifdef PLATFORM_WIN32
{
DrawLock __;
HFONT hfont = GetWin32Font(fnt, 0);
if(hfont) {
HDC hdc = Win32_IC();
HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);
TEXTMETRIC tm;
::GetTextMetrics(hdc, &tm);
if(tm.tmPitchAndFamily & TMPF_TRUETYPE) {
of.ttf = true;
int c = GetOutlineTextMetrics(hdc, 0, NULL);
if(c > 0) {
Buffer<byte> h(c);
OUTLINETEXTMETRIC *otm = (OUTLINETEXTMETRIC *)~h;
GetOutlineTextMetrics(hdc, c, otm);
of.sitalic = otm->otmItalicAngle == 0 && fnt.IsItalic();
}
}
::SelectObject(hdc, ohfont);
}
TTFReader ttf;
if(ttf.Open(fnt.GetData(), false, true)) {
of.ttf = true;
of.sitalic = ttf.post.italicAngle == 0 && fnt.IsItalic();
}
#endif
#ifdef PLATFORM_POSIX
FontInfo fi = fnt.Info();
String fn = fi.GetFileName();
String ext = ToLower(GetFileExt(fn));
if(ext == ".ttf" || ext == ".otf") {
String data = LoadFile(fn);
TTFReader ttf;
if(ttf.Open(data, false, true)) {
of.ttf = true;
of.sitalic = ttf.post.italicAngle == 0 && fnt.IsItalic();
}
}
#endif
#endif
outline_info.Add(fnt, of);
@ -410,13 +372,8 @@ void PdfDraw::DrawTextOp(int x, int y, int angle, const wchar *s, Font fnt,
if(!n) return;
if(fnt.GetHeight() == 0)
fnt.Height(100);
FontInfo ff = fnt.Info();
#ifdef PLATFORM_WIN32
int fh = ff.GetHeight() - ff.GetInternal();//TODO
#endif
#ifdef PLATFORM_POSIX
Font ff = fnt;
int fh = fnt.GetHeight();
#endif
OutlineInfo of = GetOutlineInfo(fnt);
if(of.ttf)
fnt.Height(FONTHEIGHT_TTF);
@ -439,7 +396,7 @@ void PdfDraw::DrawTextOp(int x, int y, int angle, const wchar *s, Font fnt,
Pointf prev(0, 0);
for(int i = 0; i < n; i++) {
Pointf next(Pt(x + posx * cosa + fround(ff.GetAscent() * sina)),
Pt(pgsz.cy - (y - posx * sina) - fround(ff.GetAscent() * cosa)));
Pt(pgsz.cy - (y - posx * sina) - fround(ff.GetAscent() * cosa)));
CharPos fp = GetCharPos(fnt, s[i]);
if(fi != fp.fi) {
fi = fp.fi;
@ -984,35 +941,12 @@ String PdfDraw::Finish()
}
else {
String fontbuffer;
#ifdef PLATFORM_POSIX
FontInfo fi = pdffont.GetKey(i).Info();
fontbuffer = LoadFile(fi.GetFileName());
#endif
#ifdef PLATFORM_WIN32
{
DrawLock __;
HFONT hfont = GetWin32Font(pdffont.GetKey(i), 0);
if(hfont) {
HDC hdc = Win32_IC();
HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont);
DWORD size = GetFontData(hdc, 0, 0, NULL, 0);
if(size == GDI_ERROR) {
LLOG("PdfDraw::Finish: GDI_ERROR on font " << pdffont.GetKey(i));
return Null;
}
StringBuffer b(size);
GetFontData(hdc, 0, 0, b, size);
::SelectObject(hdc, ohfont);
fontbuffer = b;
}
}
#endif
fontbuffer = pdffont.GetKey(i).GetData();
TTFReader ttf;
if(!ttf.Open(fontbuffer))
return Null;
String name = FormatIntAlpha(i + 1, true);
name.Cat('A', 6 - name.GetLength());
name << '+' << ttf.ps_name;