Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to improve speed of drawing? Very slow scene view.
-
@JonB yes, i have the file in the same folder.
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 144, in <module> [glyphs_list, variation_values]=setupGlyphs(size=512,letter='e') File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 78, in setupGlyphs basefont = c.CGFontCreateWithDataProvider(provider); File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 15, in errcheck raise Exception('{} returned void pointer with args\n{}'.format(func.__name__,args)) Exception: CGFontCreateWithDataProvider returned void pointer with args (6242820560,)```
-
added a little extra diagnostics, and tried passing provider as objcinstancee.
https://gist.github.com/b4c3e011e768320753e3c54405c56380 -
@JonB here's the traceback
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 148, in <module> [glyphs_list, variation_values]=setupGlyphs(size=512,letter='e') File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 82, in setupGlyphs basefont = c.CGFontCreateWithDataProvider(provider); File "/private/var/mobile/Containers/Shared/AppGroup/2CB744A3-0F69-40E1-A5F1-95E464DBFC21/Pythonista3/Documents/PythonistaGit/VF/64bit.py", line 15, in errcheck raise Exception('{} returned void pointer with args\n{}'.format(func.__name__,args)) Exception: CGFontCreateWithDataProvider returned void pointer with args (<b'__NSCFType': <CGDataProvider 0x17418b530>>,)```
-
How did yoy get the ttf into the device? i think this is saying the font file is invalid.
This version downloads the font directly
https://gist.github.com/7a766eb282c71bf7d27bd13fb4926482 -
@JonB there was indeed something wrong with the file. this script just crashes the app. is there a method to catch errors on crash?
-
@dgelessus has a pythonista_startup repo that installs a fault handler and uncaught exception handler which write to a fault log, so you can see which line (for segfaults and the like) or an objc stack trace in the case of objc errors (which often include a helpful message)
https://github.com/dgelessus/pythonista_startup
See the readme, there are several scripts here, personally I just use the enable_faulthandler one.
You could also set a breakpoint by long pressing in the debugger, and just keep single stepping until the crash happens.
-
https://gist.github.com/38a5434b4ebd28775dab08d181a00771
Here is a version that logs all cdll calls to glyphlog.txt. if you can post that someplace, we can see exactly what is crashing. -
@JonB thank you for hints on debugging, definetely helpful.
Here's the error log: https://gist.github.com/5bac67b24317b5e5b4badc06bee1b1c5
-
whoops, I missed one of the definitions.
https://gist.github.com/a30ddae506762c96e533f98668ad46dd
This should do it now....maybeThought for a future improvement....a CDLL which prevents calling a function unless restype and argtypes have specifically been defined.
-
@JonB unfortunatelly: https://gist.github.com/5f53f356c0c85fa9525efd13a1000198
-
well, getting close at least.
try
c.CTFontCreatePathForGlyph.restype = c_void_p
I tried to get fancy, setting restype to a callable, which maybe was a mistake.Also, I am a little wary of CGGlyph. You could try redefining that. maybe try c_int, or c_int32.
You could also try setting the transform (third argument) to None, just incase there is a problem with the CaTransform.
-
@JonB Callable
restype
s are broken and deprecated - if you setrestype
to a callable,ctypes
assumes that the return value is a 32-bit int. Most likely you didn't notice anything because you're on a 32-bit device, but on 64-bit devices this will cut off pointers and things will crash.I think the currently recommended way to do post-processing on a return value is to set
restype
to a regularctypes
type, and then set the C function'serrcheck
attribute as described in thectypes
docs (underCFUNCTYPE
probably). This will work regardless of pointer size, because you're tellingctypes
the return type viarestype
.This is another situation where
ctypes
makes default choices that silently do the wrong thing on 64-bit machines. Ifctypes
doesn't know the type of an argument or return value, it defaults to 32-bit ints instead of throwing an error. On 32-bit systems this makes life easier, because almost everything fits into 32 bits, and you almost never need type declarations this way. But on 64-bit systems everything breaks because suddenly half of all ints are 64-bit. -
ok, good to know about callable restype, that was the last one, surely.
A lot of the problems up to this point were due to me forgetting to define restype/argtypes on some parameter, which worked fine for me on 32bit. At some point I think I will subclass CDLL to ensure that argtypes/restype have been user set before allowing call, to prevent this sort of carelessness.
-
@JonB Thank you! This works very well. I won't hesitate to say it would be great to see this wrapped in python so users could open their fonts, read all the axes available and hook up a method to modify each value of the axis then use it with other tools available in Pythonista already. I am now looking up how can i build on top of what you have written. I have some questions still, please look into my comments/questions on your code: https://gist.github.com/dyyybek/810fced40405346682729e8e5568d9a3
Summing up the comments on code:
- We now have a CTFont object with variations – does it mean we could use it to set type with a layout engine as opposed to drawing paths?
- Would it be possible to use this font with standard tools in Pythonista?
Is this a place to start looking at how to set a line of text?
Using TextKitCore Text mediates between text layout and font support provided by higher level frameworks and the low-level capabilities Quartz provides to all text and font frameworks. The Quartz framework acts upon glyphs and their positions. Core Text is aware of how characters map to fonts, and it factors in information about styles, font metrics, and other attributes before it calls into Quartz to render text. Quartz is the only way to get glyphs drawn at a fundamental level, and, because Core Text provides all data in a form directly usable by Quartz, the result is high-performance text rendering.
-
I guess we should probably mve this to a git repo.... but oh well,
https://gist.github.com/5f56c0c9e16a98df04b2e23a6198b020
This version uses a ui.TextField -- editable text -- and sliders for size and weight. Then it dynamically gets CTFonts as the sliders move. I was worried this would be too slow to do in realtime, but it seems ok. fonts dont get technically get animated, but the steps seem fine enough that the effect is smooth. I wouldnt be surprised if this code leaks CTfontRefs, but things seem okay after a long time of playing with the sliders, so should be good for casual use.
BTW your PanVaria M and N seem to have issues.