On Wed, Jun 28, 2023 at 11:46 AM Werner LEMBERG <
wl@gnu.org> wrote:
>> What exactly do you want to achieve? If FreeType gets linked with
>> HarfBuzz (which you should always do), the `glyph-to-script-map`
>> property should be correctly set automatically – for SFNT-based
>> font formats, that is, which is both used by TTFs and CFFs.
>> However, you won't find any other font formats today that can be
>> universally used on all platforms.
>
> I want pygame->freetype->render_to() interface to render devnagari
> text with autofitting. That is not happening currently, and I am
> traversing the entire stack to get it done properly. I am not sure
> where the gap is? If you can give me any example code in the
> freetype code base which details the usage of "autofitter", that
> would be great.
If you have Devanagari text as input and you want correctly rendered
Devanagari as output, using FreeType directly is a bad idea. I
strongly suggest that you use a higher-level library, at least
HarfBuzz, or probably even one more level higher, that is, Pango or
ICU.
Thanks a lot for the directions. I would try Pango, During my exploration I came across Pango, HarfBuzz, Cairo, Pangocairo, I paused the trail because those are becoming too many without the knowledge of the right sequence of usage. I shall resume that trail again.
I'm not sure whether you are aware of the intricate technical
problems related to the rendering of complex scripts like Devanagari
and frieds, but handling them directly by yourself is like reinventing
the wheel.
I am not aware explicitly, but I can imagine that there may be multiple rounds of adjusting the glyphs as per the placement rules and availability of glyphs. Few are rendered left to right while others right to left the list must be long.
Irrespective of that, you should give more details on your setup, in
particular, which font you are using. Normally, if you load a glyph
with the `FT_LOAD_FORCE_AUTOHINT` flag set, the auto-hinter kicks in
while `FT_Load_Glyph` is called the first time. It uses HarfBuzz to
set up the glyph-to-script mapping, then checking whether the
necessary glyphs for the blue strings are available (see file
`afblue.dat`) so that the blue zones are correctly set up.
I did not have much insight on the above steps; however, I will build the lib in debug-mode and try to check what is happening when pygame is initiating the rendering.
Maybe you are just missing `FT_LOAD_FORCE_AUTOHINT`? You could also
compile FreeType with debugging support and set the `FT2_DEBUG`
environment variable to get more information. See file `docs/DEBUG`
for more information.
That's the plan! I shall get back with more debug data.
Best Regards
Devesh
I have the output with TRACE7, it's quite big, should I post it here or if you suggest other sharing means?
I am posting my script if you want to try at your end
import pygame
import pygame.locals
pygame.init()
screen = pygame.display.set_mode((400, 200))
clock = pygame.time.Clock()
text = f"सुरक्षा"
#font = pygame.font.Font("/usr/share/fonts/truetype/Sarai/Sarai.ttf", 50)
font = pygame.freetype.Font("/usr/share/fonts/truetype/Sarai/Sarai.ttf", 50)
#font.set_script("Deva")
surf = pygame.Surface((200, 70), pygame.locals.SRCALPHA, 32)
print(surf)
#im = font.render("प्रफुल्ल", True, "black")
#im = font.render("एक्सरसाइज", True, "black")
#print(im)
rect = font.get_rect(text, rotation=0)
im = font.render_to(surf, rect, text, rotation=0)
#print(rect)
#print(im)
#r = surf.get_rect()
#print(f'r = {r}')
#r.x += 10
#r.y += 10
#rect = surf.blit(im, r)
#print(f'rect = {rect}')
while True:
screen.fill("lightgreen")
#screen.blit(im, (0,0))
screen.blit(surf, (0,0))
#screen.blit(surf, im)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
pygame.display.flip()
clock.tick(144)
python version 3.8
pygame version 2.5.0 debug (git tag 2.5.0) [force added "FT_LOAD_FORCE_AUTOHINT|FT_LOAD_TARGET_NORMAL" in _PGFT_LoadGlyph()->get_load_flags() function]
freetype debug build 6.19
-Best Regards
Devesh