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:
- why the rect.centery need to add rect.height ?
- 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')`
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?
