2019-01-23 14:13:57 +08:00
|
|
|
|
// (C) Copyright 2017, Google Inc.
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2021-01-04 23:11:23 +08:00
|
|
|
|
#include "include_gunit.h"
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
#include "boxchar.h"
|
|
|
|
|
#include "boxread.h"
|
|
|
|
|
#include "commandlineflags.h"
|
|
|
|
|
#include "stringrenderer.h"
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2021-02-13 17:17:20 +08:00
|
|
|
|
#include <allheaders.h>
|
2021-01-04 23:11:23 +08:00
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
BOOL_PARAM_FLAG(display, false, "Display image for inspection");
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2020-12-27 17:41:48 +08:00
|
|
|
|
namespace tesseract {
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
|
|
const char kEngText[] = "the quick brown fox jumps over the lazy dog";
|
|
|
|
|
const char kHinText[] = "पिताने विवाह की | हो गई उद्विग्न वह सोचा";
|
|
|
|
|
|
2018-09-29 15:19:13 +08:00
|
|
|
|
const char kKorText[] = "이는 것으로 다시 넣을 1234 수는 있지만 선택의 의미는";
|
|
|
|
|
const char kArabicText[] =
|
|
|
|
|
"والفكر والصراع ، بالتأمل والفهم والتحليل ، "
|
2018-08-24 21:07:48 +08:00
|
|
|
|
"بالعلم والفن ، وأخيرا بالضحك أوبالبكاء ، ";
|
|
|
|
|
const char kMixedText[] = "والفكر 123 والصراع abc";
|
|
|
|
|
|
|
|
|
|
const char kEngNonLigatureText[] = "fidelity";
|
|
|
|
|
// Same as kEngNonLigatureText, but with "fi" replaced with its ligature.
|
|
|
|
|
const char kEngLigatureText[] = "fidelity";
|
|
|
|
|
|
2021-03-13 05:06:34 +08:00
|
|
|
|
static PangoFontMap *font_map;
|
2020-12-23 19:59:38 +08:00
|
|
|
|
|
2018-08-24 21:07:48 +08:00
|
|
|
|
class StringRendererTest : public ::testing::Test {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
protected:
|
2019-05-18 13:58:33 +08:00
|
|
|
|
void SetUp() override {
|
2020-12-23 19:59:38 +08:00
|
|
|
|
if (!font_map) {
|
|
|
|
|
font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
|
|
|
|
|
}
|
|
|
|
|
pango_cairo_font_map_set_default(PANGO_CAIRO_FONT_MAP(font_map));
|
2019-05-17 00:12:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 21:07:48 +08:00
|
|
|
|
static void SetUpTestCase() {
|
2021-01-11 06:21:40 +08:00
|
|
|
|
static std::locale system_locale("");
|
|
|
|
|
std::locale::global(system_locale);
|
|
|
|
|
|
2018-08-24 21:07:48 +08:00
|
|
|
|
l_chooseDisplayProg(L_DISPLAY_WITH_XZGV);
|
2019-01-23 14:13:57 +08:00
|
|
|
|
FLAGS_fonts_dir = TESTING_DIR;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
FLAGS_fontconfig_tmpdir = FLAGS_test_tmpdir;
|
2021-01-06 01:46:59 +08:00
|
|
|
|
file::MakeTmpdir();
|
|
|
|
|
PangoFontInfo::SoftInitFontConfig(); // init early
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 03:39:43 +08:00
|
|
|
|
void DisplayClusterBoxes(Image pix) {
|
2021-03-22 15:48:50 +08:00
|
|
|
|
if (!FLAGS_display) {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
return;
|
2021-03-22 15:48:50 +08:00
|
|
|
|
}
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxchars = renderer_->GetBoxes();
|
|
|
|
|
Boxa *boxes = boxaCreate(0);
|
|
|
|
|
for (const auto &boxchar : boxchars) {
|
2021-03-22 15:48:50 +08:00
|
|
|
|
if (boxchar->box()) {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
boxaAddBox(boxes, const_cast<Box *>(boxchar->box()), L_CLONE);
|
2021-03-22 15:48:50 +08:00
|
|
|
|
}
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image box_pix = pixDrawBoxaRandom(pix, boxes, 1);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
boxaDestroy(&boxes);
|
|
|
|
|
pixDisplay(box_pix, 0, 0);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
box_pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
std::unique_ptr<StringRenderer> renderer_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRenderToImage) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("UnBatang 10", 600, 600);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kKorText), renderer_->RenderToImage(kKorText, strlen(kKorText), &pix));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Lohit Hindi 10", 600, 600);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kHinText), renderer_->RenderToImage(kHinText, strlen(kHinText), &pix));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
|
|
// RTL text
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Arab 10", 600, 600);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kArabicText), renderer_->RenderToImage(kArabicText, strlen(kArabicText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
|
|
// Mixed direction Arabic + english text
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Arab 10", 600, 600);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kMixedText), renderer_->RenderToImage(kMixedText, strlen(kMixedText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRenderToImageWithUnderline) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// Underline all words but NOT intervening spaces.
|
|
|
|
|
renderer_->set_underline_start_prob(1.0);
|
|
|
|
|
renderer_->set_underline_continuation_prob(0);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->ClearBoxes();
|
|
|
|
|
|
|
|
|
|
// Underline all words AND intervening spaces.
|
|
|
|
|
renderer_->set_underline_start_prob(1.0);
|
|
|
|
|
renderer_->set_underline_continuation_prob(1.0);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->ClearBoxes();
|
|
|
|
|
|
|
|
|
|
// Underline words and intervening spaces with 0.5 prob.
|
|
|
|
|
renderer_->set_underline_start_prob(0.5);
|
|
|
|
|
renderer_->set_underline_continuation_prob(0.5);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesHandleNewlineCharacters) {
|
|
|
|
|
const char kRawText[] = "\n\n\n A \nB \nC \n\n\n";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const char kStrippedText[] = " A B C "; // text with newline chars removed
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kRawText), renderer_->RenderToImage(kRawText, strlen(kRawText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxchars = renderer_->GetBoxes();
|
2019-01-23 14:13:57 +08:00
|
|
|
|
// 3 characters + 4 spaces => 7 boxes
|
|
|
|
|
EXPECT_EQ(7, boxchars.size());
|
|
|
|
|
if (boxchars.size() == 7) {
|
|
|
|
|
// Verify the text content of the boxchars
|
|
|
|
|
for (size_t i = 0; i < boxchars.size(); ++i) {
|
|
|
|
|
EXPECT_EQ(std::string(1, kStrippedText[i]), boxchars[i]->ch());
|
|
|
|
|
}
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRenderLigatures) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Arab 12", 600, 250);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
const char kArabicLigature[] = "لا";
|
|
|
|
|
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kArabicLigature),
|
|
|
|
|
renderer_->RenderToImage(kArabicLigature, strlen(kArabicLigature), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxes = renderer_->GetBoxes();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(1, boxes.size());
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(boxes[0]->box() != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_STREQ(kArabicLigature, boxes[0]->ch().c_str());
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Arab 12", 600, 250);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
const char kArabicMixedText[] = "والفكر والصراع 1234,\nوالفكر لا والصراع";
|
|
|
|
|
renderer_->RenderToImage(kArabicMixedText, strlen(kArabicMixedText), &pix);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-13 05:06:34 +08:00
|
|
|
|
static int FindBoxCharXCoord(const std::vector<BoxChar *> &boxchars, const std::string &ch) {
|
|
|
|
|
for (const auto &boxchar : boxchars) {
|
2021-03-22 15:48:50 +08:00
|
|
|
|
if (boxchar->ch() == ch) {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
return boxchar->box()->x;
|
2021-03-22 15:48:50 +08:00
|
|
|
|
}
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
2019-01-23 14:13:57 +08:00
|
|
|
|
return INT_MAX;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, ArabicBoxcharsInLTROrder) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Arab 10", 600, 600);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// Arabic letters should be in decreasing x-coordinates
|
|
|
|
|
const char kArabicWord[] = "\u0644\u0627\u0641\u0643\u0631";
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kRevWord = "\u0631\u0643\u0641\u0627\u0644";
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->RenderToImage(kArabicWord, strlen(kArabicWord), &pix);
|
2019-01-23 14:13:57 +08:00
|
|
|
|
std::string boxes_str = renderer_->GetBoxesStr();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// Decode to get the box text strings.
|
|
|
|
|
EXPECT_FALSE(boxes_str.empty());
|
2021-03-14 03:10:46 +08:00
|
|
|
|
std::vector<std::string> texts;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_TRUE(ReadMemBoxes(0, false, boxes_str.c_str(), false, nullptr, &texts, nullptr, nullptr));
|
2019-01-23 14:13:57 +08:00
|
|
|
|
std::string ltr_str;
|
2021-03-22 15:32:09 +08:00
|
|
|
|
for (auto &text : texts) {
|
|
|
|
|
ltr_str += text.c_str();
|
2019-09-25 16:07:51 +08:00
|
|
|
|
}
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// The string should come out perfectly reversed, despite there being a
|
|
|
|
|
// ligature.
|
|
|
|
|
EXPECT_EQ(ltr_str, kRevWord);
|
|
|
|
|
// Just to prove there was a ligature, the number of texts is less than the
|
|
|
|
|
// number of unicodes.
|
|
|
|
|
EXPECT_LT(texts.size(), 5);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesOutputBoxcharsInReadingOrder) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Arab 10", 600, 600);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// Arabic letters should be in decreasing x-coordinates
|
|
|
|
|
const char kArabicWord[] = "والفكر";
|
|
|
|
|
renderer_->RenderToImage(kArabicWord, strlen(kArabicWord), &pix);
|
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxchars = renderer_->GetBoxes();
|
2019-01-23 14:13:57 +08:00
|
|
|
|
for (size_t i = 1; i < boxchars.size(); ++i) {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_GT(boxchars[i - 1]->box()->x, boxchars[i]->box()->x) << boxchars[i - 1]->ch();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
|
|
// English letters should be in increasing x-coordinates
|
|
|
|
|
const char kEnglishWord[] = "Google";
|
|
|
|
|
renderer_->ClearBoxes();
|
|
|
|
|
renderer_->RenderToImage(kEnglishWord, strlen(kEnglishWord), &pix);
|
|
|
|
|
EXPECT_EQ(boxchars.size(), strlen(kEnglishWord));
|
2019-01-23 14:13:57 +08:00
|
|
|
|
for (size_t i = 1; i < boxchars.size(); ++i) {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_LT(boxchars[i - 1]->box()->x, boxchars[i]->box()->x) << boxchars[i - 1]->ch();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
|
|
|
|
// Mixed text should satisfy both.
|
|
|
|
|
renderer_->ClearBoxes();
|
|
|
|
|
renderer_->RenderToImage(kMixedText, strlen(kMixedText), &pix);
|
2019-01-23 14:13:57 +08:00
|
|
|
|
EXPECT_LT(FindBoxCharXCoord(boxchars, "a"), FindBoxCharXCoord(boxchars, "b"));
|
|
|
|
|
EXPECT_LT(FindBoxCharXCoord(boxchars, "1"), FindBoxCharXCoord(boxchars, "2"));
|
|
|
|
|
EXPECT_GT(FindBoxCharXCoord(boxchars, "و"), FindBoxCharXCoord(boxchars, "ر"));
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRenderVerticalText) {
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("UnBatang 10", 600, 600);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->set_vertical_text(true);
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kKorText), renderer_->RenderToImage(kKorText, strlen(kKorText), &pix));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
DisplayClusterBoxes(pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Checks that we preserve charboxes across RenderToImage calls, with
|
|
|
|
|
// appropriate page numbers.
|
|
|
|
|
TEST_F(StringRendererTest, DoesKeepAllImageBoxes) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
int num_boxes_per_page = 0;
|
|
|
|
|
const int kNumTrials = 2;
|
|
|
|
|
for (int i = 0; i < kNumTrials; ++i) {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
if (!num_boxes_per_page) {
|
|
|
|
|
num_boxes_per_page = renderer_->GetBoxes().size();
|
|
|
|
|
} else {
|
2018-09-29 15:19:13 +08:00
|
|
|
|
EXPECT_EQ((i + 1) * num_boxes_per_page, renderer_->GetBoxes().size());
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
2021-03-13 05:06:34 +08:00
|
|
|
|
for (int j = i * num_boxes_per_page; j < (i + 1) * num_boxes_per_page; ++j) {
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(i, renderer_->GetBoxes()[j]->page());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesClearBoxes) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->GetBoxes().size(), 0);
|
|
|
|
|
const int num_boxes_per_page = renderer_->GetBoxes().size();
|
|
|
|
|
|
|
|
|
|
renderer_->ClearBoxes();
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(num_boxes_per_page, renderer_->GetBoxes().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesLigatureTextForRendering) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->set_add_ligatures(true);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngNonLigatureText),
|
2021-03-13 05:06:34 +08:00
|
|
|
|
renderer_->RenderToImage(kEngNonLigatureText, strlen(kEngNonLigatureText), &pix));
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2021-10-28 01:15:44 +08:00
|
|
|
|
#if 0 // not with NFC normalization
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// There should be one less box than letters due to the 'fi' ligature.
|
|
|
|
|
EXPECT_EQ(strlen(kEngNonLigatureText) - 1, renderer_->GetBoxes().size());
|
|
|
|
|
// The output box text should be ligatured.
|
|
|
|
|
EXPECT_STREQ("fi", renderer_->GetBoxes()[0]->ch().c_str());
|
2021-10-28 01:15:44 +08:00
|
|
|
|
#endif
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRetainInputLigatureForRendering) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngLigatureText),
|
2021-03-13 05:06:34 +08:00
|
|
|
|
renderer_->RenderToImage(kEngLigatureText, strlen(kEngLigatureText), &pix));
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// There should be one less box than letters due to the 'fi' ligature.
|
|
|
|
|
EXPECT_EQ(strlen(kEngNonLigatureText) - 1, renderer_->GetBoxes().size());
|
|
|
|
|
// The output box text should be ligatured.
|
|
|
|
|
EXPECT_STREQ("\uFB01", renderer_->GetBoxes()[0]->ch().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesStripUnrenderableWords) {
|
|
|
|
|
// Verdana should only be able to render the english letters and numbers in
|
|
|
|
|
// the mixed text.
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2019-01-23 14:13:57 +08:00
|
|
|
|
std::string text(kMixedText);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_GT(renderer_->StripUnrenderableWords(&text), 0);
|
|
|
|
|
EXPECT_EQ(" 123 abc", text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRenderWordBoxes) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->set_output_word_boxes(true);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kEngText), renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// Verify #boxchars = #words + #spaces
|
2021-08-07 01:45:22 +08:00
|
|
|
|
std::vector<std::string> words = split(kEngText, ' ');
|
2018-08-24 21:07:48 +08:00
|
|
|
|
const int kNumSpaces = words.size() - 1;
|
|
|
|
|
const int kExpectedNumBoxes = words.size() + kNumSpaces;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxchars = renderer_->GetBoxes();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(kExpectedNumBoxes, boxchars.size());
|
|
|
|
|
// Verify content of words and spaces
|
2019-01-23 14:13:57 +08:00
|
|
|
|
for (size_t i = 0; i < boxchars.size(); i += 2) {
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(words[i / 2], boxchars[i]->ch());
|
|
|
|
|
if (i < boxchars.size() - 1) {
|
|
|
|
|
EXPECT_EQ(" ", boxchars[i + 1]->ch());
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(boxchars[i + 1]->box() == nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRenderWordBoxesFromMultiLineText) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 600, 600);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->set_output_word_boxes(true);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
const char kMultlineText[] = "the quick brown fox\njumps over the lazy dog";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(strlen(kMultlineText), renderer_->RenderToImage(kMultlineText, strlen(kEngText), &pix));
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
// Verify #boxchars = #words + #spaces + #newlines
|
2021-08-07 01:45:22 +08:00
|
|
|
|
std::vector<std::string> words;
|
|
|
|
|
for (auto &line : split(kMultlineText, '\n')) {
|
|
|
|
|
for (auto &word : split(line, ' ')) {
|
|
|
|
|
words.push_back(word);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-24 21:07:48 +08:00
|
|
|
|
const int kNumSeparators = words.size() - 1;
|
|
|
|
|
const int kExpectedNumBoxes = words.size() + kNumSeparators;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxchars = renderer_->GetBoxes();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(kExpectedNumBoxes, boxchars.size());
|
|
|
|
|
// Verify content of words and spaces
|
2019-01-23 14:13:57 +08:00
|
|
|
|
for (size_t i = 0; i < boxchars.size(); i += 2) {
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(words[i / 2], boxchars[i]->ch());
|
2019-01-23 14:13:57 +08:00
|
|
|
|
if (i + 1 < boxchars.size()) {
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(" ", boxchars[i + 1]->ch());
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(boxchars[i + 1]->box() == nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesRenderAllFontsToImage) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 1200, 1200);
|
2019-01-23 14:13:57 +08:00
|
|
|
|
size_t offset = 0;
|
|
|
|
|
std::string font_used;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
do {
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
font_used.clear();
|
2021-03-13 05:06:34 +08:00
|
|
|
|
offset += renderer_->RenderAllFontsToImage(1.0, kEngText + offset, strlen(kEngText + offset),
|
|
|
|
|
&font_used, &pix);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
if (offset < strlen(kEngText)) {
|
2018-09-29 15:27:12 +08:00
|
|
|
|
EXPECT_TRUE(pix != nullptr);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_STRNE("", font_used.c_str());
|
|
|
|
|
}
|
2021-03-22 15:48:50 +08:00
|
|
|
|
if (FLAGS_display) {
|
2021-03-13 05:06:34 +08:00
|
|
|
|
pixDisplay(pix, 0, 0);
|
2021-03-22 15:48:50 +08:00
|
|
|
|
}
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
} while (offset < strlen(kEngText));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(StringRendererTest, DoesNotRenderWordJoiner) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 500, 200);
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string word = "A- -B C-D A BC";
|
|
|
|
|
const std::string joined_word = StringRenderer::InsertWordJoiners(word);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->RenderToImage(joined_word.c_str(), joined_word.length(), &pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxchars = renderer_->GetBoxes();
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kWordJoinerUTF8 = "\u2060";
|
2018-08-24 21:07:48 +08:00
|
|
|
|
ASSERT_EQ(word.length(), boxchars.size());
|
2019-01-23 14:13:57 +08:00
|
|
|
|
for (size_t i = 0; i < boxchars.size(); ++i) {
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_NE(kWordJoinerUTF8, boxchars[i]->ch());
|
|
|
|
|
EXPECT_EQ(word.substr(i, 1), boxchars[i]->ch());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 02:51:33 +08:00
|
|
|
|
TEST_F(StringRendererTest, DISABLED_DoesDropUncoveredChars) {
|
2021-03-15 04:06:19 +08:00
|
|
|
|
renderer_ = std::make_unique<StringRenderer>("Verdana 10", 500, 200);
|
2018-08-24 21:07:48 +08:00
|
|
|
|
renderer_->set_drop_uncovered_chars(true);
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kWord = "office";
|
|
|
|
|
const std::string kCleanWord = "oice";
|
2021-04-01 03:39:43 +08:00
|
|
|
|
Image pix = nullptr;
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_FALSE(renderer_->font().CanRenderString(kWord.c_str(), kWord.length()));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_FALSE(renderer_->font().CoversUTF8Text(kWord.c_str(), kWord.length()));
|
|
|
|
|
int offset = renderer_->RenderToImage(kWord.c_str(), kWord.length(), &pix);
|
2021-04-01 03:39:43 +08:00
|
|
|
|
pix.destroy();
|
2021-03-13 05:06:34 +08:00
|
|
|
|
const std::vector<BoxChar *> &boxchars = renderer_->GetBoxes();
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(kWord.length(), offset);
|
|
|
|
|
ASSERT_EQ(kCleanWord.length(), boxchars.size());
|
2019-01-23 14:13:57 +08:00
|
|
|
|
for (size_t i = 0; i < boxchars.size(); ++i) {
|
2018-08-24 21:07:48 +08:00
|
|
|
|
EXPECT_EQ(kCleanWord.substr(i, 1), boxchars[i]->ch());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------ StringRenderer::ConvertBasicLatinToFullwidthLatin() ------------
|
|
|
|
|
|
|
|
|
|
TEST(ConvertBasicLatinToFullwidthLatinTest, DoesConvertBasicLatin) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfAlpha = "ABCD";
|
|
|
|
|
const std::string kFullAlpha = "ABCD";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kFullAlpha, StringRenderer::ConvertBasicLatinToFullwidthLatin(kHalfAlpha));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfDigit = "0123";
|
|
|
|
|
const std::string kFullDigit = "0123";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kFullDigit, StringRenderer::ConvertBasicLatinToFullwidthLatin(kHalfDigit));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfSym = "()[]:;!?";
|
|
|
|
|
const std::string kFullSym = "()[]:;!?";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kFullSym, StringRenderer::ConvertBasicLatinToFullwidthLatin(kHalfSym));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertBasicLatinToFullwidthLatinTest, DoesNotConvertFullwidthLatin) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kFullAlpha = "ABCD";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kFullAlpha, StringRenderer::ConvertBasicLatinToFullwidthLatin(kFullAlpha));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kFullDigit = "0123";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kFullDigit, StringRenderer::ConvertBasicLatinToFullwidthLatin(kFullDigit));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kFullSym = "()[]:;!?";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kFullSym, StringRenderer::ConvertBasicLatinToFullwidthLatin(kFullSym));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertBasicLatinToFullwidthLatinTest, DoesNotConvertNonLatin) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfKana = "アイウエオ";
|
|
|
|
|
const std::string kFullKana = "アイウエオ";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfKana, StringRenderer::ConvertBasicLatinToFullwidthLatin(kHalfKana));
|
|
|
|
|
EXPECT_EQ(kFullKana, StringRenderer::ConvertBasicLatinToFullwidthLatin(kFullKana));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertBasicLatinToFullwidthLatinTest, DoesNotConvertSpace) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfSpace = " ";
|
|
|
|
|
const std::string kFullSpace = " ";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfSpace, StringRenderer::ConvertBasicLatinToFullwidthLatin(kHalfSpace));
|
|
|
|
|
EXPECT_EQ(kFullSpace, StringRenderer::ConvertBasicLatinToFullwidthLatin(kFullSpace));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------ StringRenderer::ConvertFullwidthLatinToBasicLatin() ------------
|
|
|
|
|
|
|
|
|
|
TEST(ConvertFullwidthLatinToBasicLatinTest, DoesConvertFullwidthLatin) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfAlpha = "ABCD";
|
|
|
|
|
const std::string kFullAlpha = "ABCD";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfAlpha, StringRenderer::ConvertFullwidthLatinToBasicLatin(kFullAlpha));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfDigit = "0123";
|
|
|
|
|
const std::string kFullDigit = "0123";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfDigit, StringRenderer::ConvertFullwidthLatinToBasicLatin(kFullDigit));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfSym = "()[]:;!?";
|
|
|
|
|
const std::string kFullSym = "()[]:;!?";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfSym, StringRenderer::ConvertFullwidthLatinToBasicLatin(kFullSym));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertFullwidthLatinToBasicLatinTest, DoesNotConvertBasicLatin) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfAlpha = "ABCD";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfAlpha, StringRenderer::ConvertFullwidthLatinToBasicLatin(kHalfAlpha));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfDigit = "0123";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfDigit, StringRenderer::ConvertFullwidthLatinToBasicLatin(kHalfDigit));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfSym = "()[]:;!?";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfSym, StringRenderer::ConvertFullwidthLatinToBasicLatin(kHalfSym));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertFullwidthLatinToBasicLatinTest, DoesNotConvertNonLatin) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfKana = "アイウエオ";
|
|
|
|
|
const std::string kFullKana = "アイウエオ";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfKana, StringRenderer::ConvertFullwidthLatinToBasicLatin(kHalfKana));
|
|
|
|
|
EXPECT_EQ(kFullKana, StringRenderer::ConvertFullwidthLatinToBasicLatin(kFullKana));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertFullwidthLatinToBasicLatinTest, DoesNotConvertSpace) {
|
2019-01-23 14:13:57 +08:00
|
|
|
|
const std::string kHalfSpace = " ";
|
|
|
|
|
const std::string kFullSpace = " ";
|
2021-03-13 05:06:34 +08:00
|
|
|
|
EXPECT_EQ(kHalfSpace, StringRenderer::ConvertFullwidthLatinToBasicLatin(kHalfSpace));
|
|
|
|
|
EXPECT_EQ(kFullSpace, StringRenderer::ConvertFullwidthLatinToBasicLatin(kFullSpace));
|
2018-08-24 21:07:48 +08:00
|
|
|
|
}
|
2021-03-13 05:06:34 +08:00
|
|
|
|
} // namespace tesseract
|