omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Text-Size

    Pythonista
    4
    5
    3393
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NoneNone94
      NoneNone94 last edited by

      I want to make a code which shows a text on the screen and highlights any word when you touch it. so i need a function which returns size of any word which is drawn on the screen. so far the most relevant thing i found was scene.render_text. but it gives you an image too.

      i am afraid that while computing a 300 word text, it loads 300 images (which i do not use) to the memory and have negative effect on performance.

      what do you think i can do?

      thnx

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        The best I can think of right now would be to use the <a href="http://omz-software.com/pythonista/docs/ios/ImageDraw.html">ImageDraw</a> module for drawing your text into an image (and then load that image via <a href="http://omz-software.com/pythonista/docs/ios/scene.html#scene.load_pil_image">load_pil_image</a>). The ImageDraw class has a <a href="ImageDraw.ImageDraw.textsize">textsize</a> method that you could use to calculate the width of individual words without actually having to draw them first.

        Note that if you have a device with a retina screen, you might need to double all sizes when using the ImageDraw module (because it uses a pixel coordinate system and not points).

        1 Reply Last reply Reply Quote 0
        • NoneNone94
          NoneNone94 last edited by

          Thank you. Actually i had seen the ImageDraw option but I preferred to stick to TextLayer. But I guess I have to know how images of scene.render_text are stored. As far as I realized they are not stored in the image directory so I guess they must be stored in the memory. If so if I do this:

          For x in range(len(SomeStringList))
          p=scene.render_text(SomeStringList[x],font,size)
          S[x]=p[0]
          del p

          (storing just size and deleting the scene.render_text object) will it free the memory?

          You know, actually I have the same question about remove_layer. Will remove_layer free the memory dedicated to removed layer? (because in my code I repeatedly remove and add the same layers)

          Thnx again

          1 Reply Last reply Reply Quote 0
          • polymerchm
            polymerchm last edited by

            How does the above apply when trying to draw text at a specific loction in a ui.View? I am writing a script to display fingering on a guitar,uke, etc neck and need to display note values in white on a filled black circle. The neck is set up as a custom View.

            1 Reply Last reply Reply Quote 0
            • dgelessus
              dgelessus last edited by

              This thread is from 2012 where the ui module didn't exist yet, so the above all applies only to scene scripts. With a UI you're probably best off using a ui.Label and setting its font and text_color attributes.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors