• marcin_dybas

    @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:

    1. 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?
    2. 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 TextKit

    Core 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.

    posted in Pythonista read more
  • marcin_dybas

    @JonB thank you for hints on debugging, definetely helpful.

    Here's the error log: https://gist.github.com/5bac67b24317b5e5b4badc06bee1b1c5

    posted in Pythonista read more
  • marcin_dybas

    @JonB there was indeed something wrong with the file. this script just crashes the app. is there a method to catch errors on crash?

    posted in Pythonista read more
  • marcin_dybas

    @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>>,)```

    posted in Pythonista read more
  • marcin_dybas

    @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,)```

    posted in Pythonista read more
  • marcin_dybas

    @JonB this one raises the exception from line 15

    posted in Pythonista read more
  • marcin_dybas

    @JonB i get "No method found for mutableCopy" on line 80

    posted in Pythonista read more
  • marcin_dybas

    @JonB said:

    however the issue seems to be that when you get different weights from CTfont, they are constructed differently...

    If you're trying to do this with some fonts installed on the iPad they probably won't be compatible. The paths need have the same node count and path direction. Here is my sample font with 1 weight axis:

    https://www.dropbox.com/s/cbeqxxuk9dg8jz1/PanvariaGX.ttf?dl=0

    I included all the code necessary to run the example with your interpolation method:
    https://gist.github.com/0e93006203c034a98522601644aff013
    This works very well.
    I understand that from here it is not very far to use the actual font file?

    posted in Pythonista read more
  • marcin_dybas

    @abcabc This works for me smoothly with reduction factor 2, but with reduction factor 1 the app just crashes.

    @JonB This runs very smooth! No lags at all.

    i'm starting to understand how to make use of objc_util, thanks to those examples.

    I tried above methods with a 1024 paths list. I get a memory error on dictionary creation and the script does not run.
    Path information now is only for 1 axis – interpolation between a light and bold font weight. If i want 2 axis interpolation that will quickly go to 10000 for a 100x100 different interpolations... So maybe non of these methods will actually work?

    I think my best bet is to make this script with real fonts and utilize the CTFont​Copy​Variation​Axes from CoreText.
    (https://developer.apple.com/reference/coretext/ctfont?language=objc#1666125)

    I'd be glad if someone would confirm that this is actually possible.

    posted in Pythonista read more
  • marcin_dybas

    @ccc Thanks for the optimizations. It's an iPad Air. I get under 1fps when moving fast... Is my iPad really that much slower?

    posted in Pythonista read more
  • marcin_dybas

    @abcabc All of these work very smooth with 60fps all the time.
    @JonB Each path has 29 points.

    I uploaded my project on github: https://github.com/dyyybek/pythonista
    It's in the "VariableFonts" folder.

    The list i'm using to generate the dictionary is in pathsLists.py; It's quite long, it will probably not open in Pythonista.

    posted in Pythonista read more
  • marcin_dybas

    I made a script using scene module. Basically it shows a different "image" depending on horizontal touch.location.

    from scene import *
    import ui
    
    glyphsDict = {}  # My dictionary with paths to draw
    
    class MyScene (Scene):
        def setup(self):
    
            self.myPath = ShapeNode(glyphsDict[1])  # first path to draw
            self.add_child(self.myPath)
    
            self.background_color = 'lightgrey'
    
        def touch_began(self, touch):
            x, y = touch.location
            z = int(x/(10.24/2)+1)
            self.myPath.path = glyphsDict[z]  # Setting a new path to draw
    
        def touch_moved(self, touch):
            x, y = touch.location
            z = int(x/(10.24/2)+1)
            self.myPath.path = glyphsDict[z]  # Setting a new path to draw
    
    run(MyScene())
    

    Before that i did the same using SpriteNode and swapping textures. I had 200 .gif images 7KB each (1.4MB summed up) and while the app crashed from time to time i got a rather smooth result if i "loaded" all the images by slowly moving my finger across the screen.

    The version with SpriteNode and images looked like this: https://www.instagram.com/p/BSL9ea8g0dv/

    I thought i'd move to drawing paths and the code above reflects that. My path information is 200KB so 7 times smaller that all the .gif's i was loading before. But now the animation is super slow and looks like 2fps or is not reacting at all if i move my finger very fast. On the bright side, I don't see the app crashing anymore.

    How can i improve on this? Why drawing paths is slower than loading images that are bigger?

    posted in Pythonista read more
  • marcin_dybas

    Wow what a lively community here!
    Thanks for all the responses! This works and will be very helpful.

    By the way... Here is a simulation of what i am trying to do:
    https://www.instagram.com/p/BSL9ea8g0dv/?taken-by=marcin.dybas

    Right now i'm just displaying images depending on touch location. That's already a heavy operation with 200 images and it's just one axis interpolation. I imagine drawing paths would be much faster and lightweight.

    My goal is to simulate what variable fonts can do in a fun and interactive way (i will probably incorporate motion control).

    But maybe a more than a simulation can be achieved?
    @JonB mentioned CTFontCreatePathForGlyph and while i googled it i found this under "Working With Font Variations":
    https://developer.apple.com/reference/coretext/ctfont-q6r#1666125

    Not sure if this means it is possible to open variable fonts and work with them...

    posted in Pythonista read more
  • marcin_dybas

    Hello,

    I'd like to read a bezier outline from text.
    I know i can draw a bezier path with canvas or ui.Path but i want the opposite: i want to pass a text/single letter and return it's bezier path with all the points etc...

    Is this possible in Pythonista with built in libraries?

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!