Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S SynthText
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 25
    • Issues 25
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Ankush Gupta
  • SynthText
  • Issues
  • #169
Closed
Open
Issue created Jul 24, 2019 by DeepInSearch@DeepInSearch

understanding pygame font render position

I'm trying to understand the font rendering process in render_curved(self, font, word_text) function of text_utils.py. I focus on these lines, but I can't understand why ch_bounds is computed as this, in line 189.

`

    bbs = []
    # place middle char
    rect = font.get_rect(word_text[mid_idx])
    rect.centerx = surf.get_rect().centerx
    rect.centery = surf.get_rect().centery + rect.height
    rect.centery +=  curve[mid_idx]
    ch_bounds = font.render_to(surf, rect, word_text[mid_idx], rotation=rots[mid_idx])
    ch_bounds.x = rect.x + ch_bounds.x
    ch_bounds.y = rect.y - ch_bounds.y
    mid_ch_bb = np.array(ch_bounds)`

I have something don't understand:

  1. why the rect.centery need to add rect.height ?
  2. why ch_bounds.x and ch_bounds.y have different calculation manner with ch_bounds?

I imitated this rendering process as follows: `

   import os, sys
   import pygame
   from pygame.locals import *
   from pygame import freetype

   pygame.init()
   font = freetype.Font("../font/Amiri-Bold.ttf", size=40)
   bg_surf = pygame.Surface((200,200),SRCALPHA, 32)

   display_char = "E"
   rect = font.get_rect(display_char)
   pygame.draw.rect(bg_surf, pygame.Color(128, 0, 0), rect,1)

   rect.centerx = bg_surf.get_rect().centerx
   rect.centery = bg_surf.get_rect().centery + rect.height
   pygame.draw.rect(bg_surf, pygame.Color(255, 0, 0), rect,1)

   ch_bounds = font.render_to(bg_surf, rect, display_char, rotation=0, fgcolor=(255,255,255))
   print(rect,ch_bounds)
   ch_bounds.x = rect.x + ch_bounds.x
   ch_bounds.y = rect.y - ch_bounds.y
   pygame.draw.rect(bg_surf, pygame.Color(0, 128, 0), ch_bounds,1)
   pygame.image.save(bg_surf, 'bg_surf.jpg')`

The result show like this. bg_surf

So why we don't just use this ? `

    bbs = []
    # place middle char
    rect = font.get_rect(word_text[mid_idx])
    rect.centerx = surf.get_rect().centerx
    rect.centery = surf.get_rect().centery 
    rect.centery +=  curve[mid_idx]
    ch_bounds = font.render_to(surf, rect, word_text[mid_idx], rotation=rots[mid_idx])
    ch_bounds.x = rect.x 
    ch_bounds.y = rect.y 
    mid_ch_bb = np.array(ch_bounds)`

How do you consider the position of each character?

Assignee
Assign to
Time tracking