From 4536fce9ab3fbc9eacfb87321ea19ea2df32b2e6 Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 8 Jun 2012 16:00:54 +0100 Subject: [PATCH] TextLayout RTL fix. --- modules/juce_graphics/fonts/juce_TextLayout.cpp | 11 +++++------ modules/juce_graphics/fonts/juce_TextLayout.h | 2 +- .../native/juce_win32_DirectWriteTypeLayout.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/juce_graphics/fonts/juce_TextLayout.cpp b/modules/juce_graphics/fonts/juce_TextLayout.cpp index 62d6f7bc27..d4c35bf779 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.cpp +++ b/modules/juce_graphics/fonts/juce_TextLayout.cpp @@ -232,7 +232,7 @@ void TextLayout::createLayout (const AttributedString& text, float maxWidth) if (! createNativeLayout (text)) createStandardLayout (text); - recalculateWidth(); + recalculateWidth (text); } //============================================================================== @@ -600,17 +600,16 @@ void TextLayout::createStandardLayout (const AttributedString& text) l.createLayout (text, *this); } -void TextLayout::recalculateWidth() +void TextLayout::recalculateWidth (const AttributedString& text) { - if (lines.size() > 0) + if (lines.size() > 0 && text.getReadingDirection() != AttributedString::rightToLeft) { Range range (lines.getFirst()->getLineBoundsX()); - int i; - for (i = lines.size(); --i > 0;) + for (int i = lines.size(); --i > 0;) range = range.getUnionWith (lines.getUnchecked(i)->getLineBoundsX()); - for (i = lines.size(); --i >= 0;) + for (int i = lines.size(); --i >= 0;) lines.getUnchecked(i)->lineOrigin.x -= range.getStart(); width = range.getLength(); diff --git a/modules/juce_graphics/fonts/juce_TextLayout.h b/modules/juce_graphics/fonts/juce_TextLayout.h index d051af55dd..12d1df11b7 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.h +++ b/modules/juce_graphics/fonts/juce_TextLayout.h @@ -173,7 +173,7 @@ private: void createStandardLayout (const AttributedString&); bool createNativeLayout (const AttributedString&); - void recalculateWidth(); + void recalculateWidth (const AttributedString&); JUCE_LEAK_DETECTOR (TextLayout); }; diff --git a/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp b/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp index 8dbb9b211e..2c91d4311a 100644 --- a/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp +++ b/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp @@ -77,7 +77,7 @@ namespace DirectWriteTypeLayout jassert (currentLine == layout->getNumLines()); TextLayout::Line* const newLine = new TextLayout::Line(); layout->addLine (newLine); - newLine->lineOrigin = Point (baselineOriginX, baselineOriginY); // The x value is only correct when dealing with LTR text + newLine->lineOrigin = Point (baselineOriginX, baselineOriginY); } }