diff --git a/uppsrc/CtrlCore/CocoDrawText.mm b/uppsrc/CtrlCore/CocoDrawText.mm index 07c412b4c..de2010ab3 100644 --- a/uppsrc/CtrlCore/CocoDrawText.mm +++ b/uppsrc/CtrlCore/CocoDrawText.mm @@ -7,17 +7,18 @@ namespace Upp { -CTFontRef CT_Font0(Font fnt, bool& synth) +CTFontRef CT_Font0(Font fnt, int angle, bool& synth) { CFRef s = CFStringCreateWithCString(NULL, ~fnt.GetFaceName(), kCFStringEncodingUTF8); - CFRef ctfont0 = CTFontCreateWithName(s, fnt.GetHeight(), NULL); + CGAffineTransform transform = angle ? CGAffineTransformMakeRotation(M_2PI * angle / 3600) + : CGAffineTransformIdentity; + CFRef ctfont0 = CTFontCreateWithName(s, fnt.GetHeight(), &transform); if(fnt.IsItalic() || fnt.IsBold()) { CTFontSymbolicTraits symbolicTraits = 0; if(fnt.IsBold()) symbolicTraits |= kCTFontBoldTrait; if(fnt.IsItalic()) symbolicTraits |= kCTFontItalicTrait; - CGAffineTransform transform = CGAffineTransformIdentity; CFRef ctfont = CTFontCreateCopyWithSymbolicTraits(ctfont0, fnt.GetHeight(), &transform, symbolicTraits, symbolicTraits); if(ctfont) @@ -27,10 +28,11 @@ CTFontRef CT_Font0(Font fnt, bool& synth) return ctfont0.Detach(); } -CTFontRef CT_Font(Font fnt) +CTFontRef CT_Font(Font fnt, int angle = 0) { struct Entry { Font font; + int angle; CTFontRef ctfont = NULL; bool synth = false; @@ -43,12 +45,12 @@ CTFontRef CT_Font(Font fnt) const int FONTCACHE = 64; static Entry cache[FONTCACHE]; for(int i = 0; i < FONTCACHE; i++) - if(cache[i].font == fnt) + if(cache[i].font == fnt && cache[i].angle == angle) return cache[i].ctfont; Entry& e = cache[Random(FONTCACHE)]; e.Free(); e.font = fnt; - e.ctfont = CT_Font0(fnt, e.synth); + e.ctfont = CT_Font0(fnt, angle, e.synth); return e.ctfont; } @@ -219,25 +221,24 @@ void RenderCharacterSys(FontGlyphConsumer& sw, double x, double y, int chr, Font void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) { -// DLOG("angle " << angle << ", text " << text << ", ink " << ink); - Set(ink); // needs to be here because rotation saves context... - if(angle) { - // TODO: Fix this! - CGContextSaveGState(cgHandle); - CGContextRotateCTM(cgHandle, 3 * M_PI * angle / 1800); - CGContextTranslateCTM(cgHandle, x, -y); - DrawTextOp(0, 0, 0, text, font, ink, n, dx); - CGContextRestoreGState(cgHandle); - return; - } + Set(ink); - CFRef cgFont = CTFontCopyGraphicsFont(CT_Font(font), NULL); + CFRef cgFont = CTFontCopyGraphicsFont(CT_Font(font, 0), NULL); CGContextSetFont(cgHandle, cgFont); - + Point off = GetOffset(); - x += off.x; - y = top - y - font.GetAscent() - off.y; + if(angle) { + CGAffineTransform tm = CGAffineTransformMakeTranslation(x + off.x, top - y - off.y); + tm = CGAffineTransformRotate(tm, M_2PI * angle / 3600); + CGContextSetTextMatrix(cgHandle, tm); + x = 0; + y = -font.GetAscent(); + } + else { + x += off.x; + y = top - y - font.GetAscent() - off.y; + } Buffer g(n); Buffer p(n); @@ -252,6 +253,9 @@ void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font fon CGContextSetFontSize(cgHandle, font.GetHeight()); CGContextShowGlyphsAtPositions(cgHandle, g, p, n); + + if(angle) + CGContextSetTextMatrix(cgHandle, CGAffineTransformIdentity); } }; diff --git a/uppsrc/CtrlCore/cocotodo.txt b/uppsrc/CtrlCore/cocotodo.txt index f37fef738..24f2915f3 100644 --- a/uppsrc/CtrlCore/cocotodo.txt +++ b/uppsrc/CtrlCore/cocotodo.txt @@ -1,44 +1,36 @@ sooner: -- opening FindInFiles, then selecting folder - pushing buttons does not exit dialog - -- package organizer initial size too small - minimize, maximaze - -- Ctrl+Shift+F wrong initial focus -- menubar does not loose focus after click outside (or rather ActiveFocus does not work) +- numpad Enter does not do K_ENTER +- Sort fonts - not all additional cursors are correct - Synthetise fonts -- Sort fonts - fix package organiser link options (joining link options missing space) -- numpad Enter does not do K_ENTER - - progress for assist opens too much, probably problem with delay? later: +- package organizer initial size too small - void WakeUpGuiThread(void) - fullscreen mode issues - CommonFontInfo GetFontInfoSys(Font font) metrics - GetGlyphInfoSys metrics -- ROTATED TEXT - EndSession ? - ignoreclick - event flags - CachedSetColorKeepAlpha optimize out - use NSView:needsToDrawRect: for IsPaintingOp -- implement missing Draw ops - set application icons - fix resizing arrows -- RenderCharacterSys - multimonitor support - SerializePlacement - probably improve +- implement missing Draw ops void SystemDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) void SystemDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts, int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor) void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) @@ -47,6 +39,11 @@ void SystemDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Co done: +- RenderCharacterSys +- ROTATED TEXT +- opening FindInFiles, then selecting folder - pushing buttons does not exit dialog +- menubar does not loose focus after click outside (or rather ActiveFocus does not work) +- Ctrl+Shift+F wrong initial focus - PrinterJob - reference/Reports - missing text - doubleclick interval: https://developer.apple.com/documentation/appkit/nsevent/1528384-doubleclickinterval?language=objc