PetahChristian / LionAndLamb

Lion and Lamb is an iOS app that creates word clouds using the most frequent words from a chosen book of the Bible. The app is inspired by the beautiful word clouds at Sixty-Six Clouds. The cloud layout operation generally follows the approach that Johnathan Feinberg, the creator of Wordle, described.
MIT License
35 stars 8 forks source link

Right to left text not displaying correctly #1

Open royherma opened 8 years ago

royherma commented 8 years ago

Hi and thanks for sharing this awesome repo! I'm trying to get the word cloud generator to work with a right-to-left language (Hebrew), but it isn't displaying correctly (see attached picture). Any ideas on what needs to be adjusted for it display in the same pretty way as in English?

Thanks again!

img_4659

PetahChristian commented 8 years ago

Hi Roy. Thanks for the feedback!

There are some commented out #ifdef DEBUG statements in CloudLayoutOperation.m and CloudViewController.m. If you uncomment them, bounding boxes will be drawn around individual glyphs as well as words.

The words appear to be spaced properly in the view. I suspect the text is written r-t-l, but the bounding boxes will be l-t-r (mirrored), which will throw off the hasPlacedWord:atRect: check to determine that the word placement did not intersect with any prior glyphs.

royherma commented 8 years ago

Thanks for the prompt response :)

I uncommented the debug statements, and it does look like there is a discrepancy between the glyph bounding rects and the actual word bound rects (as you mentioned). How would you go about solving this for LTF?

img_4661

PetahChristian commented 8 years ago

The problem is in addGlyphBoundingRectsToQuadTreeForWord:

    CGFloat glyphX = lineOrigin.x + glyphPosition.x + CGRectGetMinX(glyphBounds);
    CGFloat glyphY = CGRectGetHeight(horizontalFrame) - (lineOrigin.y + glyphPosition.y + CGRectGetMaxY(glyphBounds));

From the screenshot, X appears to be off by the width of the frame. r-t-l may need to be MaxX - position.x.

Y is also slightly off (by the distance between the highest ascender and the frame?). I believe l-t-r calculated a negative offset up from the bottom, but I don't understand how r-t-l would affect that value.

SalehAlDhobaie commented 8 years ago

@PetahChristian I faced the same issue that described in the above. the different between LTR & RTL is character drawing for Example the drawing of "CAR" word is start with first character which is "C" letter but in RTL specifically in Arabic if you write "صالح" the drawing will start with "ح" which is the last character in the word.even if you reverse the word if it's arabic before drawing it's not helping. because the issue with calculation with arabic. I have tried to fix the issue but I couldn't because I didn't fully understand the calculation of glyph Rects.

I have tried this code

let status = CTRunGetStatus(run) switch status { case CTRunStatus.RightToLeft: // determine if the drawing for RTL languages. break default: break }

it might help with calculation because I didn't fully understand it as I mentioned.

SalehAlDhobaie commented 7 years ago

@PetahChristian I have new update. I just did some modification for RTL specifically. it seems working fine but in some cases there is some collision between letters because the issue of rendering letters "from last to first".