Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pango_font_info_test and fix crash for MacOS with M1 #3189

Merged
merged 5 commits into from
Dec 22, 2020

Conversation

stweil
Copy link
Member

@stweil stweil commented Dec 22, 2020

No description provided.

Most parts of that test can now be used without Tensorflow code.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
The original code crashes in pango_fc_font_get_glyph on MacOS with M1.

Replacing the type cast with the macro made for that conversion
gives at least an error message before crashing:

    (process:12546): GLib-GObject-WARNING **: 08:38:02.472: invalid cast from 'PangoCairoCoreTextFont' to 'PangoFcFont'
    zsh: segmentation fault  ./pango_font_info_test

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This fixes the crash on MacOS with M1.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
@stweil
Copy link
Member Author

stweil commented Dec 22, 2020

pango_font_info_test passes on Linux. On MacOS with M1 it at least no longer crashes and passes most parts of that test.

@stweil
Copy link
Member Author

stweil commented Dec 22, 2020

See also issue #2599.

@zdenop
Copy link
Contributor

zdenop commented Dec 22, 2020

build is failing for ubuntu:

[ 92%] Building CXX object src/training/CMakeFiles/text2image.dir/pango_font_info.cpp.o
/home/travis/build/tesseract-ocr/tesseract/src/training/pango_font_info.cpp: In function ‘PangoGlyph tesseract::get_glyph(PangoFont*, gunichar)’:
/home/travis/build/tesseract-ocr/tesseract/src/training/pango_font_info.cpp:76:3: error: ‘hb_font_t’ was not declared in this scope
   hb_font_t* hb_font = pango_font_get_hb_font(font);
   ^
/home/travis/build/tesseract-ocr/tesseract/src/training/pango_font_info.cpp:76:14: error: ‘hb_font’ was not declared in this scope
   hb_font_t* hb_font = pango_font_get_hb_font(font);
              ^
/home/travis/build/tesseract-ocr/tesseract/src/training/pango_font_info.cpp:76:51: error: ‘pango_font_get_hb_font’ was not declared in this scope
   hb_font_t* hb_font = pango_font_get_hb_font(font);
                                                   ^
/home/travis/build/tesseract-ocr/tesseract/src/training/pango_font_info.cpp:77:3: error: ‘hb_codepoint_t’ was not declared in this scope
   hb_codepoint_t glyph;
   ^
/home/travis/build/tesseract-ocr/tesseract/src/training/pango_font_info.cpp:78:43: error: ‘glyph’ was not declared in this scope
   hb_font_get_nominal_glyph(hb_font, wc, &glyph);
                                           ^
/home/travis/build/tesseract-ocr/tesseract/src/training/pango_font_info.cpp:78:48:m error: ‘hb_font_get_nominal_glyph’ was not declared in this scope
   hb_font_get_nominal_glyph(hb_font, wc, &glyph);

Signed-off-by: Stefan Weil <sw@weilnetz.de>
@stweil
Copy link
Member Author

stweil commented Dec 22, 2020

The new code requires Pango 1.44 for pango_font_get_hb_font. I now added the old code as a fallback for older Pango versions, so please retry.

@amitdo
Copy link
Collaborator

amitdo commented Dec 22, 2020

pango_font_info_test passes on Linux. On MacOS with M1 it at least no longer crashes and passes most parts of that test.

Which parts do not pass? Maybe you can add TODO above each one?

@stweil
Copy link
Member Author

stweil commented Dec 22, 2020

It looks like on MacOS the test sees all MacOS fonts instead of the limited set which is installed in test/testing. I don't know the reason for that, but it explains the failure of several test steps.

[  PASSED  ] 8 tests.
[  FAILED  ] 6 tests, listed below:
[  FAILED  ] PangoFontInfoTest.CanRenderString
[  FAILED  ] PangoFontInfoTest.CanRenderLigature
[  FAILED  ] FontUtilsTest.DoesFindAvailableFonts
[  FAILED  ] FontUtilsTest.DoesDetectMissingFonts
[  FAILED  ] FontUtilsTest.DoesListAvailableFonts
[  FAILED  ] FontUtilsTest.DoesFailToSelectFont

@amitdo
Copy link
Collaborator

amitdo commented Dec 22, 2020

The text renderer was designed to work with the FontConfig backend, even on macOS, and it appears that your pango version uses the CoreText backend.

@stweil
Copy link
Member Author

stweil commented Dec 22, 2020

It's from Homebrew, and that should work with FontConfig.
text2image --list_available_fonts --fonts_dir tesseract/test/testing works.

@stweil
Copy link
Member Author

stweil commented Dec 22, 2020

[...] it appears that your pango version uses the CoreText backend.

You are right, thank you. The test passes with export PANGOCAIRO_BACKEND=fc.

@amitdo
Copy link
Collaborator

amitdo commented Dec 22, 2020

It works with text2image thanks to this code:

int main(int argc, char** argv) {
// Respect environment variable. could be:
// fc (fontconfig), win32, and coretext
// If not set force fontconfig for Mac OS.
// See https://github.com/tesseract-ocr/tesseract/issues/736
char* backend;
backend = getenv("PANGOCAIRO_BACKEND");

@zdenop zdenop merged commit b672eee into tesseract-ocr:master Dec 22, 2020
@zdenop
Copy link
Contributor

zdenop commented Dec 22, 2020

thanks

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

Successfully merging this pull request may close these issues.

3 participants