From: Joogab Yun Date: Wed, 7 Aug 2019 05:47:23 +0000 (+0900) Subject: Khmer language text is cutted in TextLabel. X-Git-Tag: dali_1.4.33~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=f45f8c7983accc407c3f400347d082d44a6b1bc5 Khmer language text is cutted in TextLabel. * Fixed an issue while retrieving the 'width' metric from complex glyphs. i.e the complex glyph 'ត់' is formed by two glyphs ( 'ត' and '់') The width of the group is calculated as the accumulated advance + the x bearing and width of the last glyph. In that case for the last glyph the accumulated advance plus the width is smaller than the width of the previous glyph. * The solution is to calculate the initial width edge and the max width edge. if HORIZONTAL_ALIGNMENT is END, this is a problem. example) TextLabel labe21 = TextLabel::New(); labe21.SetSize( 600, 100 ); labe21.SetParentOrigin(ParentOrigin::TOP_LEFT); labe21.SetAnchorPoint(AnchorPoint::TOP_LEFT); labe21.SetPosition( 100.f, 100.f); labe21.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "END" ); labe21.SetProperty(Dali::Toolkit::TextLabel::Property::TEXT, "ការកំណត់" ); stage.Add( labe21 ); Change-Id: I0a59ddc0c2c01493ea381f50310882ca9dcfc2e9 --- diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp index 20f4480..f27f4d7 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp @@ -84,6 +84,7 @@ bool LayoutTextTest( const LayoutTextData& data ) fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" ); fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" ); fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" ); + fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHindiRegular.ttf" ); // 1) Create the model. LogicalModelPtr logicalModel; @@ -5603,3 +5604,197 @@ int UtcDaliTextLayoutSetGetDefaultLineSpacing(void) tet_result(TET_PASS); END_TEST; } + +int UtcDaliTextLayoutGetGlyphMetrics(void) +{ + tet_infoline(" UtcDaliTextLayoutGetGlyphMetrics"); + + // Test retrieving metrics from group of characters + + const std::string fontFamily( "TizenSansHindi" ); + + // Set a known font description + FontDescriptionRun fontDescriptionRun01; + fontDescriptionRun01.characterRun.characterIndex = 0u; + fontDescriptionRun01.characterRun.numberOfCharacters = 2u; + fontDescriptionRun01.familyLength = fontFamily.size(); + fontDescriptionRun01.familyName = new char[fontDescriptionRun01.familyLength]; + memcpy( fontDescriptionRun01.familyName, fontFamily.c_str(), fontDescriptionRun01.familyLength ); + fontDescriptionRun01.familyDefined = true; + fontDescriptionRun01.weightDefined = false; + fontDescriptionRun01.widthDefined = false; + fontDescriptionRun01.slantDefined = false; + fontDescriptionRun01.sizeDefined = false; + + // Set a known font description + FontDescriptionRun fontDescriptionRun02; + fontDescriptionRun02.characterRun.characterIndex = 0u; + fontDescriptionRun02.characterRun.numberOfCharacters = 2u; + fontDescriptionRun02.familyLength = fontFamily.size(); + fontDescriptionRun02.familyName = new char[fontDescriptionRun02.familyLength]; + memcpy( fontDescriptionRun02.familyName, fontFamily.c_str(), fontDescriptionRun02.familyLength ); + fontDescriptionRun02.familyDefined = true; + fontDescriptionRun02.weightDefined = false; + fontDescriptionRun02.widthDefined = false; + fontDescriptionRun02.slantDefined = false; + fontDescriptionRun02.sizeDefined = false; + + // Set a known font description + FontDescriptionRun fontDescriptionRun03; + fontDescriptionRun03.characterRun.characterIndex = 0u; + fontDescriptionRun03.characterRun.numberOfCharacters = 2u; + fontDescriptionRun03.familyLength = fontFamily.size(); + fontDescriptionRun03.familyName = new char[fontDescriptionRun03.familyLength]; + memcpy( fontDescriptionRun03.familyName, fontFamily.c_str(), fontDescriptionRun03.familyLength ); + fontDescriptionRun03.familyDefined = true; + fontDescriptionRun03.weightDefined = false; + fontDescriptionRun03.widthDefined = false; + fontDescriptionRun03.slantDefined = false; + fontDescriptionRun03.sizeDefined = false; + + Vector fontDescriptionRuns01; + fontDescriptionRuns01.PushBack( fontDescriptionRun01 ); + + Vector fontDescriptionRuns02; + fontDescriptionRuns02.PushBack( fontDescriptionRun02 ); + + Vector fontDescriptionRuns03; + fontDescriptionRuns03.PushBack( fontDescriptionRun03 ); + + // Set a text area. + Size textArea(100.f, 100.f); + + + // Group: second glyph doesn't exceed the width of the first glyph + float positions01[] = { 0.f, -11.f }; + + struct LineRun line01 = + { + { 0u, 1u }, + { 0u, 1u }, + 11.f, + 15.f, + -4.f, + 0.f, + 0.f, + 0.f, + false, + false + }; + Vector lines01; + lines01.PushBack( line01 ); + + Size layoutSize01 = Vector2(11.f, 19.f); + + // Group: second glyph doesn't exceed the width of the first glyph + float positions02[] = { 0.f, -11.f , 7.f, -15.f }; + + struct LineRun line02 = + { + { 0u, 2u }, + { 0u, 2u }, + 15.f, + 15.f, + -4.f, + 0.f, + 0.f, + 0.f, + false, + false + }; + Vector lines02; + lines02.PushBack( line02 ); + + Size layoutSize02 = Vector2(15.f, 19.f); + + // Group: second glyph doesn't exceed the width of the first glyph + float positions03[] = { 0.f, -11.f , 2.f, -15.f }; + + struct LineRun line03 = + { + { 0u, 2u }, + { 0u, 2u }, + 11.f, + 15.f, + -4.f, + 0.f, + 0.f, + 0.f, + false, + false + }; + Vector lines03; + lines03.PushBack( line03 ); + + Size layoutSize03 = Vector2(11.f, 19.f); + + ///////////////////////////// + + struct LayoutTextData data[] = + { + { + "Single glyph", + "प", + textArea, + 1u, + fontDescriptionRuns01.Begin(), + layoutSize01, + 1u, + positions01, + 1u, + lines01.Begin(), + Layout::Engine::SINGLE_LINE_BOX, + 0u, + 1u, + false, + true + }, + { + "Group: second glyph exceeds the width of the first glyph", + "पो", + textArea, + 1u, + fontDescriptionRuns02.Begin(), + layoutSize02, + 2u, + positions02, + 1u, + lines02.Begin(), + Layout::Engine::SINGLE_LINE_BOX, + 0u, + 2u, + false, + true + }, + { + "Group: second glyph doesn't exceed the width of the first glyph", + "पे", + textArea, + 1u, + fontDescriptionRuns03.Begin(), + layoutSize03, + 2u, + positions03, + 1u, + lines03.Begin(), + Layout::Engine::SINGLE_LINE_BOX, + 0u, + 2u, + false, + true + } + }; + const unsigned int numberOfTests = sizeof(data)/sizeof(LayoutTextData); + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + ToolkitTestApplication application; + if( !LayoutTextTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} diff --git a/dali-toolkit/internal/text/glyph-metrics-helper.cpp b/dali-toolkit/internal/text/glyph-metrics-helper.cpp index ef9098c..b47889e 100755 --- a/dali-toolkit/internal/text/glyph-metrics-helper.cpp +++ b/dali-toolkit/internal/text/glyph-metrics-helper.cpp @@ -74,26 +74,33 @@ void GetGlyphsMetrics( GlyphIndex glyphIndex, glyphMetrics.fontId = firstGlyph.fontId; glyphMetrics.fontHeight = fontMetrics.height; - glyphMetrics.width = firstGlyph.width + ( ( firstGlyph.isItalicRequired && !isItalicFont ) ? static_cast( TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE * static_cast( firstGlyph.height ) ) : 0u ); + glyphMetrics.width = firstGlyph.width; glyphMetrics.advance = firstGlyph.advance; glyphMetrics.ascender = fontMetrics.ascender; glyphMetrics.xBearing = firstGlyph.xBearing; if( 1u < numberOfGlyphs ) { - const float widthInit = firstGlyph.xBearing; + float maxWidthEdge = firstGlyph.xBearing + firstGlyph.width; for( unsigned int i = 1u; i < numberOfGlyphs; ++i ) { const GlyphInfo& glyphInfo = *( glyphsBuffer + glyphIndex + i ); - glyphMetrics.width = glyphMetrics.advance + glyphInfo.xBearing + glyphInfo.width + ( ( firstGlyph.isItalicRequired && !isItalicFont ) ? static_cast( TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE * static_cast( firstGlyph.height ) ) : 0u ); - glyphMetrics.advance += glyphInfo.advance; + // update the initial xBearing if smaller. + glyphMetrics.xBearing = std::min( glyphMetrics.xBearing, glyphMetrics.advance + glyphInfo.xBearing ); + + // update the max width edge if bigger. + const float currentMaxGlyphWidthEdge = glyphMetrics.advance + glyphInfo.xBearing + glyphInfo.width; + maxWidthEdge = std::max( maxWidthEdge, currentMaxGlyphWidthEdge ); + glyphMetrics.advance += glyphInfo.advance; } - glyphMetrics.width -= widthInit; + glyphMetrics.width = maxWidthEdge - glyphMetrics.xBearing; } + + glyphMetrics.width += ( firstGlyph.isItalicRequired && !isItalicFont ) ? TextAbstraction::FontClient::DEFAULT_ITALIC_ANGLE * firstGlyph.height : 0.f; } } // namespace Text diff --git a/dali-toolkit/internal/text/glyph-metrics-helper.h b/dali-toolkit/internal/text/glyph-metrics-helper.h index 761ef86..6856d27 100644 --- a/dali-toolkit/internal/text/glyph-metrics-helper.h +++ b/dali-toolkit/internal/text/glyph-metrics-helper.h @@ -50,10 +50,10 @@ struct GlyphMetrics FontId fontId; ///< The font id of the glyphs. float fontHeight; ///< The font's height of those glyphs. - float width; ///< The sum of all the widths of all the glyphs. + float width; ///< The width of the group. float advance; ///< The sum of all the advances of all the glyphs. float ascender; ///< The font's ascender. - float xBearing; ///< The x bearing of the first glyph. + float xBearing; ///< The x bearing of the group. }; /**