Skip to content

Allow to input Arabic symbols in Text Layer #1621

Closed

Description

@morevnaproject

I've got this support request from a company who want to use Synfig in animation production. They are also ready to pay for this feature.

(Previously they paid for fixing issue with Arabic symbols in filenames, which I got fixed (#1517). The payment was done to OpenCollective account, see transaction dated 7/5/2020 from this company - https://opencollective.com/rafed-communication-tech-l-l-c).

They want this feature to be done within one month.
Any ideas about this? What should I answer to them? ^__^

Activity

  1. rodolforg commented on Aug 10, 2020

    @rodolforg
    Contributor

    Hm… important thing: what's wrong with current 'support'?
    How is it currently rendered?
    What is the used charset?

  2. morevnaproject commented on Aug 12, 2020

    @morevnaproject
    MemberAuthor

    I tested on Linux and see that it displays symbols in reverse sequence (this is because the text should be RTL) -
    screenshot_002

    arabic-text.sifz.zip

  3. morevnaproject commented on Aug 12, 2020

    @morevnaproject
    MemberAuthor

    ...and here is how it looks on Windows:
    screenshot_003

  4. rodolforg commented on Aug 13, 2020

    @rodolforg
    Contributor

    The problem on Windows is the selected font – it doesn't have support to arabic. User should choose one that does.

    About the text direction:

    • we could let user choose between LTR or RTL (right-to-left)
    • as text is in UTF-8, we could check if character is in range of arabic (or any other RTL language)
    • we could use harfbuzz, due to ligatures/liaison
    • we could use pango (that uses harfbuzz)
  5. morevnaproject commented on Aug 14, 2020

    @morevnaproject
    MemberAuthor

    The problem on Windows is the selected font – it doesn't have support to arabic. User should choose one that does.

    You right! I changed font and it works now!
    screenshot_003

  6. morevnaproject commented on Aug 14, 2020

    @morevnaproject
    MemberAuthor

    we could let user choose between LTR or RTL (right-to-left)

    That was my first idea too. But we will have problems with mixed strings, like this:
    screenshot_004

    And yes, we have to deal with ligatures/liaison.

    we could use pango (that uses harfbuzz)

    I think that would be the best case.

    @blackwarthog also used Pango for his prototype of Text Layer - https://repo.coolbug.org/morevna/lab/blob/master/f/c++/freetype

    Unfortunately, I have lost contact with @blackwarthog and I think he will not continue working on Text Layer. At the same time there are no license in his code repo, so I think we do not have permission to use that code directly.

  7. rodolforg commented on Aug 14, 2020

    @rodolforg
    Contributor

    Pango doesn't let us to deform character as current implementation does... AFAIK it only allows us to set font height

  8. morevnaproject commented on Aug 14, 2020

    @morevnaproject
    MemberAuthor

    Looks like it allows to deform. In Synfig 1.0.2 there was cairo-based render engine, which was using Pango.
    I have tested and it renders Arabic text correctly (with deformation) -

    screenshot_004

    This code remaining here -

    Layer_Freetype::accelerated_cairorender(Context context, cairo_t *cr, int quality, const RendDesc &renddesc, ProgressCallback *cb)const
    {
    int style=param_style.get(int());
    int weight=param_weight.get(int());
    synfig::Vector size=param_size.get(Vector());
    synfig::Real compress=param_compress.get(synfig::Real());
    synfig::Real vcompress=param_vcompress.get(synfig::Real());
    bool invert=param_invert.get(bool());
    Color color=param_color.get(Color());
    synfig::Point origin=param_origin.get(Point());
    synfig::Vector orient=param_orient.get(Vector());
    synfig::String font=param_font.get(synfig::String());
    synfig::String text=param_text.get(synfig::String());
    if(!is_solid_color())
    {
    // Initially render what's behind us
    if(!context.accelerated_cairorender(cr,quality,renddesc,cb))
    {
    if(cb)cb->error(strprintf(__FILE__"%d: Accelerated Cairo Renderer Failure",__LINE__));
    return false;
    }
    }
    RendDesc workdesc(renddesc);
    // Untransform the render desc
    if(!cairo_renddesc_untransform(cr, workdesc))
    return false;
    // New expanded workdesc values
    const int ww=workdesc.get_w();
    const int wh=workdesc.get_h();
    const double wtlx=workdesc.get_tl()[0];
    const double wtly=workdesc.get_tl()[1];
    const double wpw=workdesc.get_pw();
    const double wph=workdesc.get_ph();
    const double wsx=1/wpw;
    const double wsy=1/wph;
    const double wtx=(-wtlx+origin[0])*wsx;
    const double wty=(-wtly+origin[1])*wsy;
    // Cairo context
    cairo_surface_t* subimage = NULL;
    cairo_surface_t* inverted = NULL;
    subimage=cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, ww, wh);
    cairo_t* subcr=cairo_create(subimage);
    cairo_t* invertcr = NULL;
    if(invert)
    {
    inverted=cairo_surface_create_similar(cairo_get_target(cr), CAIRO_CONTENT_COLOR_ALPHA, ww, wh);
    invertcr=cairo_create(inverted);
    cairo_set_source_rgba(invertcr, color.get_r(), color.get_g(), color.get_b(), color.get_a());
    cairo_paint_with_alpha(invertcr, get_amount());
    }
    // Pango
    PangoLayout *layout;
    PangoFontDescription *font_description;
    // Pango Font
    font_description = pango_font_description_new ();
    pango_font_description_set_family (font_description, font.c_str());
    pango_font_description_set_weight (font_description, PangoWeight(weight));
    pango_font_description_set_style (font_description, PangoStyle(style));
    // The size is scaled to match Software render size (remove the scale?)
    Real sizex=1.75*fabs(size[0])*fabs(wsx);
    Real sizey=1.75*fabs(size[1])*fabs(wsy);
    Real vscale=sizey/sizex;
    pango_font_description_set_absolute_size (font_description, sizex * PANGO_SCALE );
    //Pango Layout
    layout = pango_cairo_create_layout (subcr);
    pango_layout_set_font_description (layout, font_description);
    pango_layout_set_text (layout, text.c_str(), -1);
    if(orient[0]<0.4)
    pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
    else if(orient[0]>0.6)
    pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
    else
    pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
    pango_layout_set_single_paragraph_mode(layout, false);
    // Calculate the logical and ink rectangles of the layout before add spacing
    PangoRectangle ink_layout, logical_layout;
    PangoRectangle ink_rect, logical_rect;
    pango_layout_get_pixel_extents(layout, &ink_layout, &logical_layout);
    // Spacing
    // Horizontal
    PangoAttrList* attrlist=pango_attr_list_new();
    Real hspace=compress>1.0?0.4*sizex*(compress-1.0):(compress<1.0)?0.5*sizex*(compress-1.0):0;
    PangoAttribute* spacing=pango_attr_letter_spacing_new(hspace*PANGO_SCALE);
    pango_attr_list_insert_before(attrlist, spacing);
    pango_layout_set_attributes(layout, attrlist);
    // Vertical
    int total_lines=pango_layout_get_line_count(layout);
    Real vspace_total=vcompress>1.0?0.4*logical_layout.height*(vcompress-1.0):(vcompress<1.0)?0.6*logical_layout.height*(vcompress-1.0):0;
    Real vspace=0;
    if(total_lines>1)
    vspace=vspace_total/(total_lines-1);
    pango_layout_set_spacing(layout, vspace*PANGO_SCALE);
    // Recalculate extents due to spacing changes
    pango_layout_get_pixel_extents(layout, &ink_layout, &logical_layout);
    // Render text
    cairo_save(subcr);
    cairo_set_source_rgba(subcr, color.get_r(), color.get_g(), color.get_b(), color.get_a());
    cairo_scale(subcr, 1.0, vscale);
    pango_cairo_update_layout(subcr, layout);
    cairo_move_to(subcr, wtx-logical_layout.width*orient[0], (wty-(logical_layout.height+vspace_total)*vscale*orient[1])/vscale);
    pango_cairo_show_layout(subcr, layout);
    // Debug ink and logical lines
    if(0)
    {
    pango_layout_get_pixel_extents(layout, &ink_rect, &logical_rect);
    // Render logical and ink rectangles
    cairo_save(subcr);
    cairo_set_source_rgb(subcr, 0.0, 1.0, 0.0);
    cairo_set_line_width(subcr, 1.0);
    cairo_rectangle(subcr, wtx+ink_rect.x-0.5-logical_layout.width*orient[0],
    wty+ink_rect.y-0.5-(logical_layout.height+vspace_total)*orient[1],
    ink_rect.width,
    ink_rect.height);
    cairo_stroke(subcr);
    cairo_restore(subcr);
    cairo_save(subcr);
    cairo_set_line_width(subcr, 1.0);
    cairo_set_source_rgb(subcr, 0.0, 0.0, 1.0);
    cairo_rectangle(subcr, wtx+logical_rect.x-0.5-logical_layout.width*orient[0],
    wty+logical_rect.y-0.5-(logical_layout.height+vspace_total)*orient[1],
    logical_rect.width,
    logical_rect.height);
    cairo_stroke(subcr);
    cairo_move_to(subcr, wtx+2, wty);
    cairo_arc(subcr, wtx, wty, 2.0, 0, 2*3.141516);
    cairo_fill(subcr);
    cairo_restore(subcr);
    }
    cairo_restore(subcr);
    cairo_save(cr);
    // Render the text on the target surface with the proper operator
    if(invert)
    {
    cairo_set_source_surface(invertcr, subimage, 0,0);
    cairo_set_operator(invertcr, CAIRO_OPERATOR_DEST_OUT);
    cairo_paint_with_alpha(invertcr, get_amount());
    }
    // Need to scale down to user coordinates before pass to cr
    cairo_translate(cr, wtlx, wtly);
    cairo_scale(cr, wpw, wph);
    if(invert)
    cairo_set_source_surface(cr, inverted, 0, 0);
    else
    cairo_set_source_surface(cr, subimage, 0, 0);
    if(is_solid_color())
    {
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint(cr);
    }
    else
    {
    cairo_paint_with_alpha_operator(cr, get_amount(), get_blend_method());
    }
    cairo_restore(cr);
    // Destroy and return
    cairo_surface_destroy(subimage);
    cairo_destroy(subcr);
    if(invert)
    {
    cairo_surface_destroy(inverted);
    cairo_destroy(invertcr);
    }
    pango_attr_list_unref(attrlist);
    g_object_unref (layout);
    pango_font_description_free (font_description);
    return true;
    }

  9. rodolforg commented on Aug 14, 2020

    @rodolforg
    Contributor

    Ok. I saw a "transformation matrix" in Pango that should the work.

  10. khaledhosny commented on Aug 14, 2020

    @khaledhosny

    Pango should be much less work to integrate (especially if you already use Cairo), and provides many needed features (RTL, font fallabck, line breaking, etc). HarfBuzz is much lower level than Pango, and will require a bit of work (and additional libraries) to get the same features.

  11. rodolforg commented on Aug 14, 2020

    @rodolforg
    Contributor

    I've found a reference implementation for raw harfbuzz:
    https://github.com/lxnt/ex-sdl-freetype-harfbuzz/blob/master/ex-sdl-freetype-harfbuzz.c

    We don't use cairo in rendering (anymore).

    Anyway, I tested a simple/draft implementation by using pango yesterday.
    I did wish to avoid it, to reduce the synfig library dependencies (keep them at low number).
    However, I don't have time now to think on how to deal BiDi texts. And cairo/pango are somehow still as a dependency for the core library.

  12. morevnaproject commented on Aug 16, 2020

    @morevnaproject
    MemberAuthor

    UPDATE: The client company has flushed away. ^__^ I have implemented a sound export feature for them, but they didn't paid according to our previous agreement. Well, we have a great feature anyway! 🤣

  13. rodolforg commented on Aug 16, 2020

    @rodolforg
    Contributor

    Captura de tela de 2020-08-16 12-34-41

    UPDATE: The client company has flushed away. ^__^

    Oh. So I'll go back to my priority list lol Cleanup header files and standardize custom widgets

  14. morevnaproject commented on Aug 16, 2020

    @morevnaproject
    MemberAuthor

    Woah!!!

  15. 7 remaining items

  16. rodolforg commented on Aug 28, 2020

    @rodolforg
    Contributor
  17. morevnaproject commented on Aug 31, 2020

    @morevnaproject
    MemberAuthor

    Thank you! I have tested it and build process fails for me when it tries to render splash screen:

    make[2]: Entering directory '/home/konstantin/sources/synfig/_production/synfig-studio/images'
    synfig --quiet splash_screen_development.sif -o splash_screen.png --time 0f
    No LADSPA plugins were found!
    
    Check your LADSPA_PATH environment variable.
    synfig(4626) [08:09:07] warning: Cannot open ./synfig_modules.cfg
    synfig(4626) [08:09:07] warning: Cannot open /home/konstantin/.local/share/synfig/synfig_modules.cfg
    /home/konstantin/sources/synfig/_production/build/bin/synfig: warning: Unable to find module "mod_libavcodec" (file not found)
    synfig(4626) [08:09:07] warning: Different pixel-per-unit value while calculation of target offset. a: TransformationAffineSW, b: LayerSW
    synfig(4626) [08:09:07] warning: Different pixel-per-unit value while calculation of target offset. a: TransformationAffineSW, b: BlurSW
    offset: 155.556478, 107.102134
    offset: 149.556478, 101.102134
    **
    Pango:ERROR:pango-layout.c:3871:pango_layout_check_lines: assertion failed: (!layout->log_attrs)
    Makefile:1455: recipe for target 'splash_screen.png' failed
    make[2]: *** [splash_screen.png] Aborted (core dumped)
    make[2]: Leaving directory '/home/konstantin/sources/synfig/_production/synfig-studio/images'
    Makefile:695: recipe for target 'all-recursive' failed
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory '/home/konstantin/sources/synfig/_production/synfig-studio'
    Makefile:531: recipe for target 'all' failed
    make: *** [all] Error 2
    

    Though, if I skip building of images it works and I was able to see correct Arabic text on workspace!

  18. rodolforg commented on Aug 31, 2020

    @rodolforg
    Contributor

    And now I'm having this problem even in master branch, even after deleting _debug folder… :(

    /home/rodolfo/projetos/synfig/synfig-studio/src/gui/dialogs/about.cpp: In constructor ‘studio::About::About()’:
    /home/rodolfo/projetos/synfig/synfig-studio/src/gui/dialogs/about.cpp:247:46: error: ‘ETL_VERSION’ was not declared in this scope; did you mean ‘FC_VERSION’?
      247 |  extra_info += etl::strprintf(_("ETL %s\n"), ETL_VERSION);
          |                                              ^~~~~~~~~~~
          |                                              FC_VERSION
    make[3]: *** [Makefile:1909: dialogs/synfigstudio-about.o] Error 1
    
  19. ice0 commented on Aug 31, 2020

    @ice0
    Collaborator

    @rodolforg Looks like it can't find config.h

    As for me, the best way to fix this is to run the script 2-build - *. sh and wait for it to complete.

  20. rodolforg commented on Aug 31, 2020

    @rodolforg
    Contributor

    I tried it too :( production version works. Debug version after cloning repo to another path too.

    I figured it out: The problem was that try I did by following the CMake instructions. It polluted my source folder (with CMakeFiles dirs, Makefile, .cmake and .cmake.in files) instead of using the suggested cmake-build dir.
    Besides, it created a etl_profile.h in (source-dir)/ETL/ETL/ that is completely different of that generated by Autotools (and it misses the ETL_version definition).

  21. morevnaproject commented on Aug 31, 2020

    @morevnaproject
    MemberAuthor

    I have made attempt to build binary on Windows (to send an early preview to the client), but it fails with the following error:

    libtool: link: g++ -shared -nostdlib C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/crtbegin.o  .libs/liblyr_freetype_la-main.o .libs/liblyr_freetype_la-lyr_freetype.o   -L/usr/x86_64-w64-mingw32/lib -LC:/GTK/lib ../../synfig/.libs/libsynfig.dll.a -LC:/msys64/mingw64/lib -LC:/msys64/opt/mlt-6.16.0/lib -lole32 -lltdl -ldl -lz -lgiomm-2.4 -lgio-2.0 -lxml++-2.6 -lxml2 -lglibmm-2.4 -lfftw3 -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lcairo -lmlt++ -lmlt -luser32 -lsigc-2.0 -lintl -lfontconfig -lfreetype -lpthread -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/../../.. -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.1.0/crtend.o  -mms-bitfields -pthread -mms-bitfields -mms-bitfields -mms-bitfields -mms-bitfields -mms-bitfields -mms-bitfields -O2 -Wl,-rpath -Wl,\$ORIGIN/lib -Wl,-no-undefined -Wl,--export-all-symbols -Wl,--subsystem=console -Wl,--enable-runtime-pseudo-reloc   -pthread -o .libs/liblyr_freetype.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/liblyr_freetype.dll.a
    .libs/liblyr_freetype_la-lyr_freetype.o:lyr_freetype.cpp:(.text+0xd6b5): undefined reference to `pango_ft2_font_map_new'
    .libs/liblyr_freetype_la-lyr_freetype.o:lyr_freetype.cpp:(.text$_ZN14Layer_Freetype10PangoStuff6renderEPN6synfig7SurfaceERKNS1_5ColorENS4_11BlendMethodEfRKNS1_6VectorESA_b[_ZN14Layer_Freetype10PangoStuff6renderEPN6synfig7SurfaceERKNS1_5ColorENS4_11BlendMethodEfRKNS1_6VectorESA_b]+0x5e4): undefined reference to `pango_ft2_render_layout'
    collect2.exe: error: ld returned 1 exit status
    make[4]: *** [Makefile:563: liblyr_freetype.la] Error 1
    make[4]: Leaving directory '/d/synfig/_production/synfig-core/src/modules/lyr_freetype'
    make[3]: *** [Makefile:567: all-recursive] Error 1
    make[3]: Leaving directory '/d/synfig/_production/synfig-core/src/modules'
    make[2]: *** [Makefile:470: all-recursive] Error 1
    make[2]: Leaving directory '/d/synfig/_production/synfig-core/src'
    make[1]: *** [Makefile:694: all-recursive] Error 1
    make[1]: Leaving directory '/d/synfig/_production/synfig-core'
    make: *** [Makefile:562: all] Error 2
    

    @ice0 any ideas why this can happen?

  22. morevnaproject commented on Aug 31, 2020

    @morevnaproject
    MemberAuthor
  23. ice0 commented on Aug 31, 2020

    @ice0
    Collaborator

    @morevnaproject looks like pango not linked. I will take a look,

  24. ice0 commented on Aug 31, 2020

    @ice0
    Collaborator

    pangoft2

    PKG_CHECK_MODULES(LIBPANGO, pango pangocairo pangoft2,[
    <------>CONFIG_DEPS="$CONFIG_DEPS pango pangocairo pangoft2"
    ],[
    <------>AC_MSG_ERROR([ ** You need to install pango])
    ])
    
  25. morevnaproject commented on Sep 1, 2020

    @morevnaproject
    MemberAuthor

    @ice0 Oooh, thank you so much!!

  26. Fahad-Alsaidi commented on Dec 30, 2020

    @Fahad-Alsaidi

    Is there any update on this?

  27. rodolforg commented on Dec 30, 2020

    @rodolforg
    Contributor

    I'm sorry I stopped to work on this due to my difficult to make the pango implementation compatible to current implementation (coordinates, size, and features).
    I may (try to) work more on it later, but not now.

  28. rodolforg commented on Oct 16, 2021

    @rodolforg
    Contributor

    @morevnaproject we can close this issue?

  29. morevnaproject commented on Oct 17, 2021

    @morevnaproject
    MemberAuthor

    Yes! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions