mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Developing new draw
git-svn-id: svn://ultimatepp.org/upp/trunk@1365 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
91de873684
commit
dbbabbca75
5 changed files with 73 additions and 284 deletions
|
|
@ -4,219 +4,4 @@
|
|||
|
||||
#ifdef PLATFORM_X11
|
||||
|
||||
static FT_Library sFTlib;
|
||||
|
||||
bool sInitFt(void)
|
||||
{
|
||||
if(sFTlib)
|
||||
return true;
|
||||
return FT_Init_FreeType(&sFTlib) == 0;
|
||||
}
|
||||
|
||||
FcPattern *CreateFcPattern(Font font, int angle)
|
||||
{
|
||||
LTIMING("CreateXftFont");
|
||||
double sina, cosa;
|
||||
int hg = abs(font.GetHeight());
|
||||
if(hg == 0) hg = 10;
|
||||
String n = font.GetFaceName();
|
||||
const char *face = n;
|
||||
FcPattern *p = FcPatternCreate();
|
||||
FcPatternAddString(p, FC_FAMILY, (FcChar8*)face);
|
||||
FcPatternAddInteger(p, FC_SLANT, font.IsItalic() ? 110 : 0);
|
||||
FcPatternAddInteger(p, FC_PIXEL_SIZE, hg);
|
||||
FcPatternAddInteger(p, FC_WEIGHT, font.IsBold() ? 200 : 100);
|
||||
FcPatternAddBool(p, FC_MINSPACE, 1);
|
||||
if(angle) {
|
||||
FcMatrix mx;
|
||||
Draw::SinCos(angle, sina, cosa);
|
||||
mx.xx = cosa;
|
||||
mx.xy = -sina;
|
||||
mx.yx = sina;
|
||||
mx.yy = cosa;
|
||||
FcPatternAddMatrix(p, FC_MATRIX, &mx);
|
||||
}
|
||||
FcResult result;
|
||||
FcPattern *m = XftFontMatch(Xdisplay, Xscreenno, p, &result);
|
||||
FcPatternDestroy(p);
|
||||
return m;
|
||||
}
|
||||
|
||||
FT_Face CreateFTFace(const FcPattern *pattern, String *rpath) {
|
||||
FT_Face face = NULL;
|
||||
|
||||
int id;
|
||||
double dsize;
|
||||
double aspect;
|
||||
FcChar8 *filename;
|
||||
|
||||
if(!sInitFt())
|
||||
return NULL;
|
||||
|
||||
if(FcPatternGetString(pattern, FC_FILE, 0, &filename) != FcResultMatch)
|
||||
return NULL;
|
||||
|
||||
if(rpath)
|
||||
*rpath = (const char *)filename;
|
||||
|
||||
if(FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &dsize) != FcResultMatch)
|
||||
dsize = 16;
|
||||
|
||||
if (FcPatternGetDouble(pattern, FC_ASPECT, 0, &aspect) != FcResultMatch)
|
||||
aspect = 1.0;
|
||||
|
||||
FT_F26Dot6 ysize = (FT_F26Dot6) (dsize * 64.0);
|
||||
FT_F26Dot6 xsize = (FT_F26Dot6) (dsize * aspect * 64.0);
|
||||
|
||||
if(FT_New_Face (sFTlib, (const char *)filename, 0, &face))
|
||||
return NULL;
|
||||
|
||||
FT_Set_Char_Size(face, xsize, ysize, 0, 0);
|
||||
return face;
|
||||
}
|
||||
|
||||
#define FONTCACHE 37
|
||||
|
||||
struct FtFaceEntry {
|
||||
Font font;
|
||||
FT_Face face;
|
||||
String path;
|
||||
};
|
||||
|
||||
FT_Face FTFace(Font fnt, String *rpath = NULL)
|
||||
{
|
||||
RTIMING("FTFace");
|
||||
DDUMP(fnt);
|
||||
static FtFaceEntry cache[FONTCACHE];
|
||||
ONCELOCK {
|
||||
for(int i = 0; i < FONTCACHE; i++)
|
||||
cache[i].font.Height(-30000);
|
||||
}
|
||||
FtFaceEntry be;
|
||||
be = cache[0];
|
||||
for(int i = 0; i < FONTCACHE; i++) {
|
||||
FtFaceEntry e = cache[i];
|
||||
if(i)
|
||||
cache[i] = be;
|
||||
if(e.font == fnt) {
|
||||
if(rpath)
|
||||
*rpath = e.path;
|
||||
if(i)
|
||||
cache[0] = e;
|
||||
return e.face;
|
||||
}
|
||||
be = e;
|
||||
}
|
||||
RTIMING("FTFace2");
|
||||
if(be.face) {
|
||||
LOG("Removing " << be.font << " - " << (void *)be.face);
|
||||
FT_Done_Face(be.face);
|
||||
}
|
||||
be.font = fnt;
|
||||
FcPattern *p = CreateFcPattern(fnt, 0);
|
||||
be.face = CreateFTFace(p, &be.path);
|
||||
FcPatternDestroy(p);
|
||||
cache[0] = be;
|
||||
if(rpath)
|
||||
*rpath = be.path;
|
||||
for(int i = 0; i < FONTCACHE; i++)
|
||||
LOG(i << ": " << cache[i].font);
|
||||
return be.face;
|
||||
}
|
||||
|
||||
CommonFontInfo GetFontInfoSys(Font font)
|
||||
{
|
||||
CommonFontInfo fi;
|
||||
|
||||
FT_Face face = FTFace(font, &fi.path);
|
||||
if(face) {
|
||||
fi.ascent = face->size->metrics.ascender >> 6;
|
||||
fi.descent = -(face->size->metrics.descender >> 6);
|
||||
fi.height = fi.ascent + fi.descent;
|
||||
fi.lineheight = face->size->metrics.height >> 6;
|
||||
fi.external = 0;
|
||||
fi.internal = 0;
|
||||
fi.overhang = 0;
|
||||
fi.maxwidth = face->size->metrics.max_advance >> 6;
|
||||
fi.avewidth = fi.maxwidth;
|
||||
fi.default_char = '?';
|
||||
fi.fixedpitch = font.GetFaceInfo() & Font::FIXEDPITCH;
|
||||
int hg = abs(font.GetHeight());
|
||||
if(hg == 0) hg = 10;
|
||||
fi.underline_thickness = max(hg / 20, 1);
|
||||
fi.underline_position = max(hg / 15, int(fi.descent > 0));
|
||||
}
|
||||
return fi;
|
||||
}
|
||||
|
||||
#define FLOOR(x) ((x) & -64)
|
||||
#define CEIL(x) (((x)+63) & -64)
|
||||
#define TRUNC(x) ((x) >> 6)
|
||||
#define ROUND(x) (((x)+32) & -64)
|
||||
|
||||
GlyphInfo GetGlyphInfoSys(Font font, int chr)
|
||||
{
|
||||
RTIMING("GetGlyphInfoSys");
|
||||
GlyphInfo gi;
|
||||
FT_Face face = FTFace(font, NULL);
|
||||
gi.lspc = gi.rspc = 0;
|
||||
gi.width = 0x8000;
|
||||
if(face) {
|
||||
RTIMING("GetGlyphInfoSys 2");
|
||||
int glyph_index = FT_Get_Char_Index(face, chr);
|
||||
if(glyph_index &&
|
||||
(FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP) == 0 ||
|
||||
FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT) == 0)) {
|
||||
FT_Glyph_Metrics& m = face->glyph->metrics;
|
||||
int left = FLOOR(m.horiBearingX);
|
||||
int width = TRUNC(CEIL(m.horiBearingX + m.width) - left);
|
||||
gi.width = TRUNC(ROUND(face->glyph->advance.x));
|
||||
gi.lspc = TRUNC(left);
|
||||
gi.rspc = gi.width - width - gi.lspc;
|
||||
}
|
||||
}
|
||||
return gi;
|
||||
}
|
||||
|
||||
Vector<FaceInfo> GetAllFacesSys()
|
||||
{
|
||||
static const char *basic_fonts[] = {
|
||||
"sans-serif",
|
||||
"serif",
|
||||
"sans-serif",
|
||||
"monospace",
|
||||
"serif",
|
||||
"sans-serif",
|
||||
"monospace",
|
||||
};
|
||||
|
||||
Vector<FaceInfo> list;
|
||||
for(int i = 0; i < __countof(basic_fonts); i++) {
|
||||
FaceInfo& fi = list.Add();
|
||||
fi.name = basic_fonts[i];
|
||||
fi.info = (i == 3 || i == 6) ? Font::SCALEABLE|Font::FIXEDPITCH : Font::SCALEABLE;
|
||||
}
|
||||
FcPattern *p = FcPatternCreate();
|
||||
FcObjectSet *os = FcObjectSetBuild(XFT_FAMILY, XFT_SPACING, XFT_SCALABLE, (void *)0);
|
||||
FcFontSet *fs = FcFontList(NULL, p, os);
|
||||
FcPatternDestroy(p);
|
||||
FcObjectSetDestroy(os);
|
||||
for(int i = 0; i < fs->nfont; i++) {
|
||||
FcChar8 *family = NULL;
|
||||
if(FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) == 0 && family) {
|
||||
FaceInfo& fi = list.Add();
|
||||
fi.name = (const char *)family;
|
||||
fi.info = 0;
|
||||
int iv;
|
||||
if(FcPatternGetInteger(fs->fonts[i], FC_SPACING, 0, &iv) == 0 && iv == FC_MONO)
|
||||
fi.info |= Font::FIXEDPITCH;
|
||||
FcBool bv;
|
||||
if(FcPatternGetBool(fs->fonts[i], FC_SCALABLE, 0, &bv) == 0 && bv)
|
||||
fi.info |= Font::SCALEABLE;
|
||||
}
|
||||
}
|
||||
FcFontSetDestroy(fs);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
|
||||
"main.cpp";
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
main.cpp charset "UTF-8";
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
|
|
|
|||
4
uppdev/Prompt/init
Normal file
4
uppdev/Prompt/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _Prompt_icpp_init_stub
|
||||
#define _Prompt_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#endif
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
// CtrlImg::Set(CtrlImg::I_information, Win32Icon(IDI_INFORMATION));
|
||||
PromptOK("Test");
|
||||
// CtrlImg::Reset();
|
||||
// PromptOK("Test");
|
||||
}
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
// CtrlImg::Set(CtrlImg::I_information, Win32Icon(IDI_INFORMATION));
|
||||
PromptOK("Test 自由的百科全书,可以由用户编辑");
|
||||
// CtrlImg::Reset();
|
||||
// PromptOK("Test");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,49 +1,49 @@
|
|||
#include <RichEdit/RichEdit.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
String FileName()
|
||||
{
|
||||
// return "d:/test.qtf";
|
||||
return GetExeDirFile("test.qtf");
|
||||
}
|
||||
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
// ChClassicSkin();
|
||||
// ChStdSkin();
|
||||
// SetLanguage(LNG_('P','L','P','L'));
|
||||
|
||||
// InstallCrashDump();
|
||||
|
||||
DUMP(GUI_PopUpEffect());
|
||||
RichEditWithToolBar e;
|
||||
Vector<int> h;
|
||||
for(int i = 0; i < Font::GetFaceCount(); i++)
|
||||
h.Add(i);
|
||||
e.FontFaces(h);
|
||||
|
||||
DUMP(ScrollBarSize());
|
||||
|
||||
e.Pick(ParseQTF(LoadFile(FileName())));
|
||||
RichEdit::PosInfo f;
|
||||
LoadFromFile(f, ConfigFile("pos"));
|
||||
e.SetPosInfo(f);
|
||||
// e.Pick(ParseQTF(AsQTF(CreateImageObject(CtrlImg::exclamation)) + " hahahaha"));
|
||||
TopWindow w;
|
||||
w.SetRect(0, 0, 700, 500);
|
||||
w.Sizeable().Zoomable();
|
||||
w.Add(e.SizePos());
|
||||
w.Run();
|
||||
/*
|
||||
String strQTF = e.GetQTF(CHARSET_ISO8859_1);
|
||||
e.SetQTF(strQTF);
|
||||
w.Run();
|
||||
*/
|
||||
String x = e.GetQTF();
|
||||
SaveFile(FileName(), x);
|
||||
f = e.GetPosInfo();
|
||||
StoreToFile(f, ConfigFile("pos"));
|
||||
LOG("Exit");
|
||||
}
|
||||
#include <RichEdit/RichEdit.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
String FileName()
|
||||
{
|
||||
// return "d:/test.qtf";
|
||||
return GetExeDirFile("test.qtf");
|
||||
}
|
||||
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
// ChClassicSkin();
|
||||
// ChStdSkin();
|
||||
// SetLanguage(LNG_('P','L','P','L'));
|
||||
|
||||
// InstallCrashDump();
|
||||
|
||||
DUMP(GUI_PopUpEffect());
|
||||
RichEditWithToolBar e;
|
||||
Vector<int> h;
|
||||
for(int i = 1; i < Font::GetFaceCount(); i++)
|
||||
h.Add(i);
|
||||
e.FontFaces(h);
|
||||
|
||||
DUMP(ScrollBarSize());
|
||||
|
||||
e.Pick(ParseQTF(LoadFile(FileName())));
|
||||
RichEdit::PosInfo f;
|
||||
LoadFromFile(f, ConfigFile("pos"));
|
||||
e.SetPosInfo(f);
|
||||
// e.Pick(ParseQTF(AsQTF(CreateImageObject(CtrlImg::exclamation)) + " hahahaha"));
|
||||
TopWindow w;
|
||||
w.SetRect(0, 0, 700, 500);
|
||||
w.Sizeable().Zoomable();
|
||||
w.Add(e.SizePos());
|
||||
w.Run();
|
||||
/*
|
||||
String strQTF = e.GetQTF(CHARSET_ISO8859_1);
|
||||
e.SetQTF(strQTF);
|
||||
w.Run();
|
||||
*/
|
||||
String x = e.GetQTF();
|
||||
SaveFile(FileName(), x);
|
||||
f = e.GetPosInfo();
|
||||
StoreToFile(f, ConfigFile("pos"));
|
||||
LOG("Exit");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue