-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a drawSimpleText() method to the Canvas class. (#39)
* Add a drawSimpleText() method to the Canvas class. * Fix build error.
- Loading branch information
Showing
17 changed files
with
221 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making tgfx available. | ||
// | ||
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/BSD-3-Clause | ||
// | ||
// 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. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "tgfx/core/Typeface.h" | ||
#include "tgfx/utils/UTF.h" | ||
|
||
namespace tgfx { | ||
GlyphID Typeface::getGlyphID(const std::string& name) const { | ||
if (name.empty()) { | ||
return 0; | ||
} | ||
auto count = UTF::CountUTF8(name.c_str(), name.size()); | ||
if (count <= 0) { | ||
return 0; | ||
} | ||
const char* start = name.data(); | ||
auto unichar = UTF::NextUTF8(&start, start + name.size()); | ||
return getGlyphID(unichar); | ||
} | ||
} // namespace tgfx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making tgfx available. | ||
// | ||
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/BSD-3-Clause | ||
// | ||
// 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. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "SimpleTextShaper.h" | ||
#include "tgfx/utils/UTF.h" | ||
|
||
namespace tgfx { | ||
std::pair<std::vector<GlyphID>, std::vector<Point>> SimpleTextShaper::Shape( | ||
const std::string& text, const tgfx::Font& font) { | ||
const char* textStart = text.data(); | ||
const char* textStop = textStart + text.size(); | ||
std::vector<GlyphID> glyphs = {}; | ||
std::vector<Point> positions = {}; | ||
auto emptyGlyphID = font.getGlyphID(" "); | ||
auto emptyAdvance = font.getAdvance(emptyGlyphID); | ||
float xOffset = 0; | ||
while (textStart < textStop) { | ||
auto unichar = UTF::NextUTF8(&textStart, textStop); | ||
auto glyphID = font.getGlyphID(unichar); | ||
if (glyphID > 0) { | ||
glyphs.push_back(glyphID); | ||
positions.push_back(Point::Make(xOffset, 0.0f)); | ||
auto advance = font.getAdvance(glyphID); | ||
xOffset += advance; | ||
} else { | ||
xOffset += emptyAdvance; | ||
} | ||
} | ||
return {glyphs, positions}; | ||
} | ||
} // namespace tgfx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making tgfx available. | ||
// | ||
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/BSD-3-Clause | ||
// | ||
// 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. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include "tgfx/core/Font.h" | ||
|
||
namespace tgfx { | ||
class SimpleTextShaper { | ||
public: | ||
static std::pair<std::vector<GlyphID>, std::vector<Point>> Shape(const std::string& text, | ||
const Font& font); | ||
}; | ||
} // namespace tgfx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.