Re: [ft] Rendering Arabic
Thanks so much Simon, I'm getting the right glyphs now (both Arabic and English) :D I do have one last problem now though, which is that all the characters are vertically aligned along the top of the line (also both Arabic and English). For almost every glyph, libraqm gives an 'x_offset' and 'y_offset' of '0', so I'm not sure how to vertically align the glyphs properly. Example text: [image: image.png] Thanks again, Tim On Thu, 14 Nov 2019 at 11:25, Simon Cozens wrote: > On 14/11/2019 11:21, Tim Orton wrote: > > 1) I am no longer getting any Arabic characters, and the English > > characters are all wrong too. (Admittedly I was expecting the English > > text to go wrong because I am hard-coding libraqm to use Arabic). > > This was my fault - when I said FT_Load_Char I should have said > FT_Load_Glyph. > > > 2) The character metrics libraqm returns are unusable - for example the > > x advance libraqm gives for most characters is between 200 and 900, > > whereas the x advance I was getting from freetype is usually less than > > 10 - so the result is that all the characters are incredibly far spread > out. > > These metrics are in font units, so you need to scale them - divide by > the font's units-per-em (face->units_per_EM) and multiply by the font size. > > S > -- t.or...@ososim.com +44 (0)1223 421034 *O**SO* *SIM* learning brought to life www.ososim.com Ososim Limited, Registered in England and Wales No. 06608651. Registered Office: St John's Innovation Centre, Cowley Road, Cambridge, CB4 0WS
Re: [ft] Rendering Arabic
Hello, Thanks for your response, but unfortunately I'm not getting the results I expected: 1) I am no longer getting any Arabic characters, and the English characters are all wrong too. (Admittedly I was expecting the English text to go wrong because I am hard-coding libraqm to use Arabic). - Instead of Arabic characters, I am getting mostly symbols, blank spaces and occasional capital English letters. Instead of English text, I am only getting Capital English letters, and the wrong letters at that. 2) The character metrics libraqm returns are unusable - for example the x advance libraqm gives for most characters is between 200 and 900, whereas the x advance I was getting from freetype is usually less than 10 - so the result is that all the characters are incredibly far spread out. I am getting the glyph data from libraqm in my text rendering method (below), and within that method, I am calling a method called GetGlyphPixmap (further below) which calls FT_Load_Char. My text rendering method looks like this at the moment: int TextManager::RenderText(const std::string& text, const FontType font_type, const FontStyle font_style, const int x, const int y, const int max_width, const Vector4& colour) { const unsigned int font_slot = font_style & FONT_STYLE_MASK; Font* font = m_font_grid[font_type][font_slot]; static const float wfactor = 1.0f / float(TEXTURE_WIDTH); static const float hfactor = 1.0f / float(TEXTURE_HEIGHT); int width = 0; size_t position = 0; int origin_x = x; const int origin_y = y; const auto rq = raqm_create (); if (nullptr == rq || !raqm_set_text_utf8(rq, text.c_str(), strlen(text.c_str())) || !raqm_set_freetype_face(rq, font->ftface) || !raqm_set_par_direction(rq, RAQM_DIRECTION_RTL) || !raqm_set_language(rq, "ar", 0, strlen(text.c_str())) || !raqm_layout(rq)) { return 0; } size_t count; raqm_glyph_t *glyphs = raqm_get_glyphs (rq, &count); for (size_t i = 0; i < count; ++i) { CharacterInfo* info = new CharacterInfo(); info->advance = glyphs[i].x_advance; info->bearing_x = glyphs[i].x_offset; info->bearing_y = glyphs[i].y_offset; info->texture_x = -1;// Mark as not having been rendered to a texture yet info->texture_y = -1;// Mark as not having been rendered to a texture yet if ((max_width > 0.0f) && ((width + info->advance) > max_width)) { // Bail if this character won't fit (and we asked for width to be checked) break; } if (info->texture_x < 0) { // This character has not been rendered to a texture yet... // Get an RGBA pixmap for the character's glyph // Row 0 of the generated pixmap represents the topmost part of the glyph // Column 0 of the generated pixmap represents the leftmost part of the glyph if (!GetGlyphPixmap(glyphs[i], BOX_SIZE, BOX_SIZE, m_rgba_pixmap_buffer)) continue; // Upload the RGBA pixmap to the texture at the current slot m_texture_manager->ActivateTexture(m_current_texture); m_texture_manager->UpdateTexture(m_current_texture_x, m_current_texture_y, BOX_SIZE, BOX_SIZE, m_rgba_pixmap_buffer); // Store the details of the texture and the position used to store the glyph info->texture = m_current_texture; info->texture_x = m_current_texture_x; info->texture_y = m_current_texture_y; // Get ready with a new slot m_current_texture_x += BOX_SIZE; if (m_current_texture_x == TEXTURE_WIDTH) { m_current_texture_x = 0; m_current_texture_y += BOX_SIZE; if (m_current_texture_y == TEXTURE_HEIGHT) { // The current texture is full, create a new one m_texture_manager->CreateTexture(TEXTURE_WIDTH, TEXTURE_HEIGHT, m_current_texture); m_textures.push_back(m_current_texture); m_current_texture_y = 0; } } } const float left = (float)(origin_x + info->bearing_x); const float top = (float)(origin_y + font->leading + (font->ascent - info->bearing_y)); FloatRectangle coords(left, top, left + BOX_SIZE, top + BOX_SIZE); // slight texcoord corrections for bilinear filtering const bool needsOffset(m_rectangle_batcher->GetRTTFrame() || !ApproxEquals(m_rectangle_batcher->GetPointPixelScale(), 1.0f)); const float beginOffset = needsOffset ? -1.0f : 0.0001f; const float endOffset = needsOffset ? -0.5f : -0.0001f; const float tleft = (info->texture_x +beginOffset)*wfactor; const float ttop= (info->texture_y +beginOffset)*hfactor; const float tright = (info->texture_x + BOX_SIZE +endOffset)*wfactor; const float tbottom = (info->texture_y + BOX_SIZE +endOffset)*hfactor; FloatRectangle texcoords(tleft, ttop, tright, tbottom); m_rectangle_batcher->AddRectangle(coords, texcoords, colour, info->texture); origin_x += info->advance; width+= info->advance; } if ((font_style & FONT_STYLE_UNDERLINE) && (width > 0)) { const float x1 = (float)(x); const float x2 = (float)(x + width); const float py = (float)(y + font->leading + font->ascent - font->descent) - 0.5f; const Vector2 start(x1, py); const Vector2 end(x2, py); m_line_batcher->AddLine(start, end, colour, colour, 1.0f); } raqm_destroy(rq); return width; } And the method GetGlyphP
Re: [ft] Rendering Arabic
On Mon, 4 Nov 2019 10:30:19 + Simon Cozens wrote: > So, you've already got the glyph selection and positioning > information from libraqm. That's step one. Step two depends on a bit > on what kind of canvas you're rendering onto, but the basic idea is > that you can now (using freetype) select the glyph from the font by > ID: > > FT_Load_Char( face, glyph_index, FT_LOAD_DEFAULT ); Does libraqm return character codes or glyph IDs? If it's glyph IDs, shouldn't that be: FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT ); Or am I misunderstanding something? - Derek
Re: [ft] Rendering Arabic
On 04/11/2019 10:19, Tim Orton wrote: I can render simple text with freetype, and I have just started using libraqm for glyph shaping, for complex text. Basically, I can get information from libraqm about the glyph index, offset, advance, etc... but I don't know how to use that to get the bitmap of the glyph to render. Sorry this question is more about libraqm than freetype, but I can't find another community to ask this question. Hi again Tim, Actually, this *is* a freetype question! There is a division of labour between the shaping engine and the glyph rendering engine. Shaping (libraqm) tells you what glyph you want and where to put it. Rendering tells you what it looks like. So, you've already got the glyph selection and positioning information from libraqm. That's step one. Step two depends on a bit on what kind of canvas you're rendering onto, but the basic idea is that you can now (using freetype) select the glyph from the font by ID: FT_Load_Char( face, glyph_index, FT_LOAD_DEFAULT ); and then you can get its bitmap as you normally would and position it onto your canvas in the place that libraqm told you to put it. Hope that is clearer - if not, keep asking (you may need to show some code)! Simon
Re: [ft] Rendering Arabic
Hello freetype community, Does anyone here know how to use libraqm with freetype (to render Arabic text)? I can render simple text with freetype, and I have just started using libraqm for glyph shaping, for complex text. Basically, I can get information from libraqm about the glyph index, offset, advance, etc... but I don't know how to use that to get the bitmap of the glyph to render. Sorry this question is more about libraqm than freetype, but I can't find another community to ask this question. Thanks, Tim Orton On Thu, 15 Aug 2019 at 16:19, Simon Cozens wrote: > On 05/08/2019 10:39, Tim Orton wrote: > > Can anyone tell me how to render Arabic text using FreeType2? > > The main issue is that with Arabic, characters have different forms > > depending on whether they are at the start, middle or end of a word. (I > > think this is called "glyph joining", is that correct?) > > More generally, selecting the right glyph from the font according to > text-level considerations is called "shaping", but we know what you > mean. :-) > > > FreeType doesn't seem to handle this natively, so I think I need to use > > another library to handle it, such as Pango or FriBidi > > Right, you will need a shaping engine. The open source shaping engine is > Harfbuzz, and it is available under the MIT license so you will be able > to use it in commercial projects. Fribidi is available under the LGPL, > so using it as a library does not require you to disclose your source. > > You might also find libraqm (also MIT licensed) a more helpful > high-level library for laying out Arabic; it interfaces between > freetype, harfbuzz and fribidi. > -- t.or...@ososim.com +44 (0)1223 421034 *O**SO* *SIM* learning brought to life www.ososim.com Ososim Limited, Registered in England and Wales No. 06608651. Registered Office: St John's Innovation Centre, Cowley Road, Cambridge, CB4 0WS
Re: [ft] Rendering Arabic
On 05/08/2019 10:39, Tim Orton wrote: Can anyone tell me how to render Arabic text using FreeType2? The main issue is that with Arabic, characters have different forms depending on whether they are at the start, middle or end of a word. (I think this is called "glyph joining", is that correct?) More generally, selecting the right glyph from the font according to text-level considerations is called "shaping", but we know what you mean. :-) FreeType doesn't seem to handle this natively, so I think I need to use another library to handle it, such as Pango or FriBidi Right, you will need a shaping engine. The open source shaping engine is Harfbuzz, and it is available under the MIT license so you will be able to use it in commercial projects. Fribidi is available under the LGPL, so using it as a library does not require you to disclose your source. You might also find libraqm (also MIT licensed) a more helpful high-level library for laying out Arabic; it interfaces between freetype, harfbuzz and fribidi. ___ Freetype mailing list Freetype@nongnu.org https://lists.nongnu.org/mailman/listinfo/freetype
Re: [ft] rendering arabic string inopengl using free type 2
Hello, You can try this : http://sourceforge.net/projects/ftgl/develop It will allow you to render font in opengl. I've ever tried it and it works really fine. Moreover it's based on FreeType so you could render Arabic font. 2010/6/13 Erik Möller > Try this, I haven't checked out this particular lesson in detail, but NeHe > generally has very well explained and easy tutorials. > > http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43 > > Also, if you haven't already you should check out the three tutorials at > > http://www.freetype.org/freetype2/docs/tutorial/step1.html > > That should at least get you started. > > Regards, > Erik > > On Jun 12, 2010, at 11:41 PM, engineer ims wrote: > > > Hi,I want to render arabic text in opengl using free type 2 can you help > me by a code how do it,please help me > > > > > > > > > > > > thanks > > ___ > > Freetype mailing list > > Freetype@nongnu.org > > http://lists.nongnu.org/mailman/listinfo/freetype > > > ___ > Freetype mailing list > Freetype@nongnu.org > http://lists.nongnu.org/mailman/listinfo/freetype > ___ Freetype mailing list Freetype@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype
Re: [ft] rendering arabic string inopengl using free type 2
Try this, I haven't checked out this particular lesson in detail, but NeHe generally has very well explained and easy tutorials. http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43 Also, if you haven't already you should check out the three tutorials at http://www.freetype.org/freetype2/docs/tutorial/step1.html That should at least get you started. Regards, Erik On Jun 12, 2010, at 11:41 PM, engineer ims wrote: > Hi,I want to render arabic text in opengl using free type 2 can you help me > by a code how do it,please help me > > > > > > thanks > ___ > Freetype mailing list > Freetype@nongnu.org > http://lists.nongnu.org/mailman/listinfo/freetype ___ Freetype mailing list Freetype@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype
Re: [ft] rendering arabic string inopengl using free type 2
> Hi,I want to render arabic text in opengl using free type 2 can you > help me by a code how do it,please help me Please contact an OpenGL mailig list. FreeType is too low-level a library to be of help for you. Werner ___ Freetype mailing list Freetype@nongnu.org http://lists.nongnu.org/mailman/listinfo/freetype