2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <dali/dali.h>
21 #include <dali/integration-api/glyph-set.h>
23 #include <dali-test-suite-utils.h>
25 // Internal headers are allowed here
27 #include <dali/internal/event/text/font-impl.h>
28 #include <dali/internal/event/resources/resource-ticket.h>
29 #include <dali/internal/event/common/thread-local-storage.h>
33 // Called only once before first test is run.
34 void utc_dali_internal_font_startup()
36 test_return_value = TET_UNDEF;
39 // Called only once after last test is run
40 void utc_dali_internal_font_cleanup()
42 test_return_value = TET_PASS;
49 static const char* TestText = "Some text";
52 Integration::GlyphMetrics characters[] =
54 {' ', 1, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f},
55 {'S', 1, 10.0f, 20.0f, 0.0f, 1.0f, 12.0f},
56 {'o', 1, 11.0f, 20.0f, 0.0f, 1.0f, 13.0f},
57 {'m', 1, 12.0f, 20.0f, 0.0f, 1.0f, 14.0f},
58 {'e', 1, 13.0f, 20.0f, 0.0f, 1.0f, 15.0f},
59 {'t', 1, 14.0f, 20.0f, 0.0f, 1.0f, 16.0f},
60 {'x', 1, 15.0f, 20.0f, 0.0f, 1.0f, 17.0f} };
62 static Integration::GlyphSet* BuildGlyphSet()
64 Integration::GlyphSet* set = new Integration::GlyphSet();
65 Integration::BitmapPtr bitmapData;
67 for (unsigned int index = 0; index < sizeof(characters)/sizeof(characters[0]); index++)
69 set->AddCharacter(bitmapData, characters[index]);
72 set->mLineHeight = 20.0f;
73 set->mUnitsPerEM = 2048.0f/64.0f;
78 static Font CreateFont(TestApplication& application)
80 Integration::GlyphSet* glyphSet = BuildGlyphSet();
81 Integration::ResourcePointer resourcePtr(glyphSet); // reference it
83 // Don't use a font which could be cached otherwise cached values will be used making measure text test to fail.
84 Font font = Font::New(FontParameters("TET-FreeSans", "Book", PointSize(8)));
85 application.SendNotification(); // Send to update thread
86 application.Render(16); // Process request
87 application.Render(16); // Resource complete
88 application.SendNotification(); // Update event objects
89 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
93 } //anonymous namespace
96 int UtcDaliFontMeasureTextWidth(void)
98 TestApplication application;
100 tet_infoline("Testing Dali::Font::MeasureTextWidth()");
102 Font testFont = CreateFont(application);
103 float width = testFont.MeasureTextWidth(TestText, 30.0f);
105 DALI_TEST_EQUALS(width, 270.0f, 0.001f, TEST_LOCATION);
109 int UtcDaliFontMeasureTextWidthNegative(void)
111 TestApplication application;
113 tet_infoline("Testing Dali::Font::MeasureTextWidth() with negative height");
115 Font testFont = CreateFont(application);
116 float width = testFont.MeasureTextWidth(TestText, -30.0f);
118 DALI_TEST_EQUALS(width, 0.0f, TEST_LOCATION);
122 int UtcDaliFontMeasureTextHeight(void)
124 TestApplication application;
126 tet_infoline("Testing Dali::Font::MeasureTextHeight()");
128 Font testFont = CreateFont(application);
129 float height = testFont.MeasureTextHeight(TestText, 200.0f);
131 DALI_TEST_EQUALS(height, 22.2222f, 0.001f, TEST_LOCATION);
135 int UtcDaliFontMeasureTextHeightNegative(void)
137 TestApplication application;
139 tet_infoline("Testing Dali::Font::MeasureTextHeight() with negative width");
141 Font testFont = CreateFont(application);
142 float height = testFont.MeasureTextHeight(TestText, -200.0f);
144 DALI_TEST_EQUALS(height, 0.0f, TEST_LOCATION);