Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Users
    • Groups
    • Solved
    • Unsolved
    • Search
    1. Home
    2. Southbank
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Southbank

    @Southbank

    0
    Reputation
    1
    Posts
    1
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Southbank Follow

    Best posts made by Southbank

    This user hasn't posted anything yet.

    Latest posts made by Southbank

    • Question: Repeat 'apply formatting' function to style paragraphs of text

      Hello, everyone!

      Working on a project that will hopefully involve typesetting a printed book using Drawbot, some experience of python but probably a novice by most standards.

      Does anyone have a good suggestion of how to repeat a formatting find/replace function to identify all instances of a word within a longer text that could be italicised/colour changed for example. This would have to work for multiple words/phrases.

      I have managed to find this great example below from @gferreira but cant work out how to repeat something like this to identify and change multiple instances? Any help would be much appreciated,

      txt = '''Some title here
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tempus justo in finibus condimentum. Proin vitae mauris ac nibh elementum consectetur. Aenean justo mi, cursus vel placerat vitae, gravida in mi.
      '''
      
      def applyFormatting(formattedString, findText, styleDict):
      
          start = str(formattedString).find(findText)
          end = start + len(findText)
          
          before = formattedString[:start]
          after  = formattedString[end:]
      
          replaceText = formattedString.copy()
          replaceText.clear()
          replaceText.append(findText, **styleDict)
      
          return before + replaceText + after
      
      T = FormattedString(txt, fontSize=36, font="Arial")
      
      T = applyFormatting(T, 'Some title here', dict(fontSize=72, font='Times New Roman', paragraphBottomSpacing=20))
      T = applyFormatting(T, 'sit amet', dict(font='Arial Bold', fill=(1, 0, 0),))
      T = applyFormatting(T, 'condimentum', dict(font='Arial Italic', fill=(0, 1, 0),))
      
      while len(T):
          newPage('A4')
          T = textBox(T, (20, 20, width() - 40, height() - 40))
      posted in General Discussion
      Southbank
      Southbank