From 18bd1f3b001872de190c8baf3209fd310dab3b6b Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 3 Aug 2018 16:44:39 +0000 Subject: [PATCH] CtrlCore, ide: Cocoa Ctrl+Space issue, CT_Font caching git-svn-id: svn://ultimatepp.org/upp/trunk@12142 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/CocoDrawText.mm | 43 +++++++++++++++++++++++++++------ uppsrc/CtrlCore/cocotodo.txt | 18 ++++++-------- uppsrc/ide/ide.key | 2 +- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/uppsrc/CtrlCore/CocoDrawText.mm b/uppsrc/CtrlCore/CocoDrawText.mm index c84d5d7b5..2ef6b8b80 100644 --- a/uppsrc/CtrlCore/CocoDrawText.mm +++ b/uppsrc/CtrlCore/CocoDrawText.mm @@ -7,8 +7,8 @@ namespace Upp { -CTFontRef CT_Font(Font fnt) -{ // TODO: Caching (?) +CTFontRef CT_Font0(Font fnt, bool& synth) +{ CFRef s = CFStringCreateWithCString(NULL, ~fnt.GetFaceName(), kCFStringEncodingUTF8); CFRef ctfont0 = CTFontCreateWithName(s, fnt.GetHeight(), NULL); if(fnt.IsItalic() || fnt.IsBold()) { @@ -18,12 +18,40 @@ CTFontRef CT_Font(Font fnt) if(fnt.IsItalic()) symbolicTraits |= kCTFontItalicTrait; CGAffineTransform transform = CGAffineTransformIdentity; - return CTFontCreateCopyWithSymbolicTraits(ctfont0, fnt.GetHeight(), + CFRef ctfont = CTFontCreateCopyWithSymbolicTraits(ctfont0, fnt.GetHeight(), &transform, symbolicTraits, symbolicTraits); + if(ctfont) + return ctfont.Detach(); + synth = true; } return ctfont0.Detach(); } +CTFontRef CT_Font(Font fnt) +{ + struct Entry { + Font font; + CTFontRef ctfont = NULL; + bool synth = false; + + void Free() { if(ctfont) CFRelease(ctfont); ctfont = NULL; } + + Entry() { font.Height(-22222); } + ~Entry() { Free(); } + }; + + const int FONTCACHE = 64; + static Entry cache[FONTCACHE]; + for(int i = 0; i < FONTCACHE; i++) + if(cache[i].font == fnt) + return cache[i].ctfont; + Entry& e = cache[Random(FONTCACHE)]; + e.Free(); + e.font = fnt; + e.ctfont = CT_Font0(fnt, e.synth); + return e.ctfont; +} + GlyphInfo GetGlyphInfoSys(CTFontRef ctfont, int chr) { GlyphInfo gi; @@ -49,7 +77,7 @@ CommonFontInfo GetFontInfoSys(Font font) { CommonFontInfo fi; String path; - CFRef ctfont = CT_Font(font); + CTFontRef ctfont = CT_Font(font); if(ctfont) { #if 0 DDUMP(font); @@ -84,7 +112,7 @@ CommonFontInfo GetFontInfoSys(Font font) GlyphInfo GetGlyphInfoSys(Font font, int chr) { LTIMING("GetGlyphInfoSys"); - CFRef ctfont = CT_Font(font); + CTFontRef ctfont = CT_Font(font); return GetGlyphInfoSys(ctfont, chr); } @@ -151,9 +179,8 @@ void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font fon CGContextRestoreGState(cgHandle); return; } - - CFRef ctfont = CT_Font(font); - CFRef cgFont = CTFontCopyGraphicsFont(ctfont, NULL); + + CFRef cgFont = CTFontCopyGraphicsFont(CT_Font(font), NULL); CGContextSetFont(cgHandle, cgFont); diff --git a/uppsrc/CtrlCore/cocotodo.txt b/uppsrc/CtrlCore/cocotodo.txt index e76813174..6a1cf299b 100644 --- a/uppsrc/CtrlCore/cocotodo.txt +++ b/uppsrc/CtrlCore/cocotodo.txt @@ -1,11 +1,7 @@ sooner: -- X11 on option -- OSX flag -- flagCOCOA -- USEMALLOC - - triple click, hold... +- Ctrl+Space assist - package organizer initial size too small - rect loop (ViewDraw) @@ -15,28 +11,24 @@ sooner: - not all additional cursors are correct - Synthetise fonts - Sort fonts +- fix link options (joining link options missing space) later: - void WakeUpGuiThread(void) - fullscreen mode issues -- missing cursors (add to iml, use undocumented cursor) - PrinterJob - DrawDragRect -- CT_Font caching - CommonFontInfo GetFontInfoSys(Font font) metrics - ROTATED TEXT - GetGlyphInfoSys metrics - EndSession ? -- Image::Arrow etc... - ignoreclick - event flags - CachedSetColorKeepAlpha optimize out - use NSView:needsToDrawRect: for IsPaintingOp - implement missing Draw ops -- fix rotated text -- fix link options (joining link options missing space) - set application icons - fix resizing arrows - RenderCharacterSys @@ -53,6 +45,11 @@ void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Co done: +- CT_Font caching +- X11 on option +- OSX flag +- flagCOCOA +- USEMALLOC - ide: Alt+Tab does not work - Ctrl+Tab - Ctrl+Mouse wheel @@ -81,3 +78,4 @@ done: - Open/OpenMain variants - initial focus - Switch does not seem to work for some reason +- Image::Arrow etc... diff --git a/uppsrc/ide/ide.key b/uppsrc/ide/ide.key index d0072e25b..4b94205ac 100644 --- a/uppsrc/ide/ide.key +++ b/uppsrc/ide/ide.key @@ -93,7 +93,7 @@ KEY(QTF, "QTF designer", K_ALT_Q) KEY(XML, "XML view", K_ALT_X) KEY(JSON, "JSON view", K_ALT_N) KEY(ASERRORS, "Interpret text as error list", 0) -KEY(ASSIST, "Assist", ' '|K_CTRL) +KEY(ASSIST, "Assist", K_CTRL|K_SPACE) KEY(ABBR, "Complete abbreviation", K_CTRL_PERIOD) KEY(GO_TO_LINE, "Go to line..", K_CTRL|K_SHIFT_G) KEY(DCOPY, "Copy as definition/declaration", K_ALT_C)