aboutsummaryrefslogtreecommitdiff
path: root/src/platform/graphics
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-10-17 12:06:14 +0800
committerYuqian Yang <crupest@crupest.life>2025-10-17 12:06:14 +0800
commit32aa6f116acc6e3e20a1ec76cef45b29f7005ad7 (patch)
tree892b71060a88b58d9293d78033000b05818783df /src/platform/graphics
parentfaf77949e19dc0d01f75bf8abb783eda70328048 (diff)
downloadcru-32aa6f116acc6e3e20a1ec76cef45b29f7005ad7.tar.gz
cru-32aa6f116acc6e3e20a1ec76cef45b29f7005ad7.tar.bz2
cru-32aa6f116acc6e3e20a1ec76cef45b29f7005ad7.zip
Remove String stage 1.
Diffstat (limited to 'src/platform/graphics')
-rw-r--r--src/platform/graphics/CMakeLists.txt2
-rw-r--r--src/platform/graphics/Geometry.cpp14
-rw-r--r--src/platform/graphics/SvgGeometryBuilderMixin.cpp37
-rw-r--r--src/platform/graphics/cairo/CairoGraphicsFactory.cpp4
-rw-r--r--src/platform/graphics/cairo/CairoImageFactory.cpp2
-rw-r--r--src/platform/graphics/cairo/CairoPainter.cpp24
-rw-r--r--src/platform/graphics/cairo/CairoResource.cpp6
-rw-r--r--src/platform/graphics/cairo/PangoFont.cpp9
-rw-r--r--src/platform/graphics/cairo/PangoTextLayout.cpp56
-rw-r--r--src/platform/graphics/direct2d/ImageFactory.cpp2
-rw-r--r--src/platform/graphics/direct2d/Painter.cpp24
-rw-r--r--src/platform/graphics/direct2d/TextLayout.cpp4
-rw-r--r--src/platform/graphics/quartz/Factory.cpp2
-rw-r--r--src/platform/graphics/quartz/ImageFactory.cpp2
-rw-r--r--src/platform/graphics/quartz/Painter.cpp22
-rw-r--r--src/platform/graphics/quartz/TextLayout.cpp2
-rw-r--r--src/platform/graphics/web_canvas/Painter.cpp2
17 files changed, 96 insertions, 118 deletions
diff --git a/src/platform/graphics/CMakeLists.txt b/src/platform/graphics/CMakeLists.txt
index 43ef80e0..e86e9c89 100644
--- a/src/platform/graphics/CMakeLists.txt
+++ b/src/platform/graphics/CMakeLists.txt
@@ -1,8 +1,6 @@
add_library(CruPlatformGraphics
- ForDllExport.cpp
Geometry.cpp
Image.cpp
- NullPainter.cpp
SvgGeometryBuilderMixin.cpp
)
target_compile_definitions(CruPlatformGraphics PRIVATE CRU_PLATFORM_GRAPHICS_EXPORT_API)
diff --git a/src/platform/graphics/Geometry.cpp b/src/platform/graphics/Geometry.cpp
index 2c842a6e..e88577ce 100644
--- a/src/platform/graphics/Geometry.cpp
+++ b/src/platform/graphics/Geometry.cpp
@@ -1,6 +1,7 @@
#include "cru/platform/graphics/Geometry.h"
#include "cru/base/Exception.h"
+#include "cru/base/String.h"
#include "cru/platform/Exception.h"
#include "cru/platform/graphics/Factory.h"
@@ -15,7 +16,7 @@ bool IGeometry::StrokeContains(float width, const Point& point) {
std::unique_ptr<IGeometry> IGeometry::CreateStrokeGeometry(
[[maybe_unused]] float width) {
- throw PlatformUnsupportedException(GetPlatformIdUtf8(), "CreateStrokeGeometry",
+ throw PlatformUnsupportedException(GetPlatformId(), "CreateStrokeGeometry",
"Create stroke geometry of a geometry is "
"not supported on this platform.");
}
@@ -207,7 +208,7 @@ const std::unordered_set<char16_t> kSvgPathDataCommands = {
'S', 's', 'Q', 'q', 'T', 't', 'A', 'a', 'Z', 'z'};
}
-void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
+void IGeometryBuilder::ParseAndApplySvgPathData(std::string_view path_d) {
Index position = 0;
const auto size = path_d.size();
@@ -236,8 +237,9 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
Index processed_count = 0;
- auto result = path_d.substr(position).ParseToFloat(
- &processed_count, StringToNumberFlags::kAllowTrailingJunk);
+ auto result = String::FromUtf8(path_d.substr(position))
+ .ParseToFloat(&processed_count,
+ StringToNumberFlags::kAllowTrailingJunk);
if (std::isnan(result)) throw Exception("Invalid svg path data number.");
@@ -252,7 +254,7 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
return Point(x, y);
};
- auto do_command = [&, this](char16_t command) {
+ auto do_command = [&, this](char command) {
last_command = command;
last_is_cubic = false;
last_is_quad = false;
@@ -442,7 +444,7 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
}
std::unique_ptr<IGeometry> CreateGeometryFromSvgPathData(
- IGraphicsFactory* factory, StringView path_d) {
+ IGraphicsFactory* factory, std::string_view path_d) {
auto builder = factory->CreateGeometryBuilder();
builder->ParseAndApplySvgPathData(path_d);
return builder->Build();
diff --git a/src/platform/graphics/SvgGeometryBuilderMixin.cpp b/src/platform/graphics/SvgGeometryBuilderMixin.cpp
index 73290da5..0863e5eb 100644
--- a/src/platform/graphics/SvgGeometryBuilderMixin.cpp
+++ b/src/platform/graphics/SvgGeometryBuilderMixin.cpp
@@ -1,7 +1,7 @@
#include "cru/platform/graphics/SvgGeometryBuilderMixin.h"
#include "cru/platform/Exception.h"
-#include "cru/base/Format.h"
+#include <string>
namespace cru::platform::graphics {
SvgGeometryBuilderMixin::SvgGeometryBuilderMixin() {}
@@ -10,34 +10,34 @@ SvgGeometryBuilderMixin::~SvgGeometryBuilderMixin() {}
Point SvgGeometryBuilderMixin::GetCurrentPosition() {
throw PlatformUnsupportedException(
- GetPlatformIdUtf8(), "GetCurrentPosition",
+ GetPlatformId(), "GetCurrentPosition",
"Svg-based geometry does not support get current position.");
}
void SvgGeometryBuilderMixin::MoveTo(const Point& point) {
- AppendCommand(u"M");
+ AppendCommand("M");
Append(point);
}
void SvgGeometryBuilderMixin::RelativeMoveTo(const Point& offset) {
- AppendCommand(u"m");
+ AppendCommand("m");
Append(offset);
}
void SvgGeometryBuilderMixin::LineTo(const Point& point) {
- AppendCommand(u"L");
+ AppendCommand("L");
Append(point);
}
void SvgGeometryBuilderMixin::RelativeLineTo(const Point& offset) {
- AppendCommand(u"l");
+ AppendCommand("l");
Append(offset);
}
void SvgGeometryBuilderMixin::CubicBezierTo(const Point& start_control_point,
const Point& end_control_point,
const Point& end_point) {
- AppendCommand(u"C");
+ AppendCommand("C");
Append(start_control_point);
Append(end_control_point);
Append(end_point);
@@ -46,7 +46,7 @@ void SvgGeometryBuilderMixin::CubicBezierTo(const Point& start_control_point,
void SvgGeometryBuilderMixin::RelativeCubicBezierTo(
const Point& start_control_offset, const Point& end_control_offset,
const Point& end_offset) {
- AppendCommand(u"c");
+ AppendCommand("c");
Append(start_control_offset);
Append(end_control_offset);
Append(end_offset);
@@ -54,14 +54,14 @@ void SvgGeometryBuilderMixin::RelativeCubicBezierTo(
void SvgGeometryBuilderMixin::QuadraticBezierTo(const Point& control_point,
const Point& end_point) {
- AppendCommand(u"Q");
+ AppendCommand("Q");
Append(control_point);
Append(end_point);
}
void SvgGeometryBuilderMixin::RelativeQuadraticBezierTo(
const Point& control_offset, const Point& end_offset) {
- AppendCommand(u"q");
+ AppendCommand("q");
Append(control_offset);
Append(end_offset);
}
@@ -69,7 +69,7 @@ void SvgGeometryBuilderMixin::RelativeQuadraticBezierTo(
void SvgGeometryBuilderMixin::ArcTo(const Point& radius, float angle,
bool is_large_arc, bool is_clockwise,
const Point& end_point) {
- AppendCommand(u"A");
+ AppendCommand("A");
Append(radius.x);
Append(radius.y);
Append(angle);
@@ -82,7 +82,7 @@ void SvgGeometryBuilderMixin::RelativeArcTo(const Point& radius, float angle,
bool is_large_arc,
bool is_clockwise,
const Point& end_offset) {
- AppendCommand(u"a");
+ AppendCommand("a");
Append(radius.x);
Append(radius.y);
Append(angle);
@@ -92,14 +92,15 @@ void SvgGeometryBuilderMixin::RelativeArcTo(const Point& radius, float angle,
}
void SvgGeometryBuilderMixin::CloseFigure(bool close) {
- if (close) AppendCommand(u"z");
+ if (close) AppendCommand("z");
}
-void SvgGeometryBuilderMixin::ParseAndApplySvgPathData(StringView path_d) {
+void SvgGeometryBuilderMixin::ParseAndApplySvgPathData(
+ std::string_view path_d) {
AppendCommand(path_d);
}
-void SvgGeometryBuilderMixin::AppendCommand(StringView command) {
+void SvgGeometryBuilderMixin::AppendCommand(std::string_view command) {
current_ += command;
current_ += u' ';
}
@@ -110,14 +111,14 @@ void SvgGeometryBuilderMixin::Append(bool flag) {
}
void SvgGeometryBuilderMixin::Append(float number) {
- current_ += cru::ToString(number);
+ current_ += std::to_string(number);
current_ += u' ';
}
void SvgGeometryBuilderMixin::Append(const Point& point) {
- current_ += cru::ToString(point.x);
+ current_ += std::to_string(point.x);
current_ += u',';
- current_ += cru::ToString(point.y);
+ current_ += std::to_string(point.y);
current_ += u' ';
}
} // namespace cru::platform::graphics
diff --git a/src/platform/graphics/cairo/CairoGraphicsFactory.cpp b/src/platform/graphics/cairo/CairoGraphicsFactory.cpp
index 11d2e734..7414e14f 100644
--- a/src/platform/graphics/cairo/CairoGraphicsFactory.cpp
+++ b/src/platform/graphics/cairo/CairoGraphicsFactory.cpp
@@ -32,13 +32,13 @@ CairoGraphicsFactory::CreateGeometryBuilder() {
return std::make_unique<CairoGeometryBuilder>(this);
}
-std::unique_ptr<IFont> CairoGraphicsFactory::CreateFont(String font_family,
+std::unique_ptr<IFont> CairoGraphicsFactory::CreateFont(std::string font_family,
float font_size) {
return std::make_unique<PangoFont>(this, std::move(font_family), font_size);
}
std::unique_ptr<ITextLayout> CairoGraphicsFactory::CreateTextLayout(
- std::shared_ptr<IFont> font, String text) {
+ std::shared_ptr<IFont> font, std::string text) {
auto text_layout = std::make_unique<PangoTextLayout>(this, std::move(font));
text_layout->SetText(std::move(text));
return text_layout;
diff --git a/src/platform/graphics/cairo/CairoImageFactory.cpp b/src/platform/graphics/cairo/CairoImageFactory.cpp
index ff922e77..6225247a 100644
--- a/src/platform/graphics/cairo/CairoImageFactory.cpp
+++ b/src/platform/graphics/cairo/CairoImageFactory.cpp
@@ -212,7 +212,7 @@ std::unique_ptr<IImage> CairoImageFactory::DecodeFromStream(
void CairoImageFactory::EncodeToStream(IImage* image, io::Stream* stream,
ImageFormat format, float quality) {
- auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformIdUtf8());
+ auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformId());
if (format == ImageFormat::Png) {
EncodePng(cairo_image->GetCairoSurface(), stream);
diff --git a/src/platform/graphics/cairo/CairoPainter.cpp b/src/platform/graphics/cairo/CairoPainter.cpp
index 94111098..d043e686 100644
--- a/src/platform/graphics/cairo/CairoPainter.cpp
+++ b/src/platform/graphics/cairo/CairoPainter.cpp
@@ -56,7 +56,7 @@ void CairoPainter::Clear(const Color& color) {
void CairoPainter::DrawLine(const Point& start, const Point& end, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -71,7 +71,7 @@ void CairoPainter::DrawLine(const Point& start, const Point& end, IBrush* brush,
void CairoPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -85,7 +85,7 @@ void CairoPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush,
void CairoPainter::FillRectangle(const Rect& rectangle, IBrush* brush) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -99,7 +99,7 @@ void CairoPainter::FillRectangle(const Rect& rectangle, IBrush* brush) {
void CairoPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -122,7 +122,7 @@ void CairoPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush,
void CairoPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -145,8 +145,8 @@ void CairoPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) {
void CairoPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformIdUtf8());
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformId());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_path = cairo_geometry->GetCairoPath();
auto cairo_pattern = cairo_brush->GetCairoPattern();
@@ -162,8 +162,8 @@ void CairoPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
void CairoPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
CheckValidation();
- auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformIdUtf8());
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformId());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_path = cairo_geometry->GetCairoPath();
auto cairo_pattern = cairo_brush->GetCairoPattern();
@@ -181,9 +181,9 @@ void CairoPainter::DrawText(const Point& offset, ITextLayout* text_layout,
CheckValidation();
auto pango_text_layout =
- CheckPlatform<PangoTextLayout>(text_layout, GetPlatformIdUtf8());
+ CheckPlatform<PangoTextLayout>(text_layout, GetPlatformId());
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
@@ -196,7 +196,7 @@ void CairoPainter::DrawText(const Point& offset, ITextLayout* text_layout,
void CairoPainter::DrawImage(const Point& offset, IImage* image) {
CheckValidation();
- auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformIdUtf8());
+ auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformId());
cairo_save(cairo_);
cairo_set_source_surface(cairo_, cairo_image->GetCairoSurface(), 0, 0);
cairo_new_path(cairo_);
diff --git a/src/platform/graphics/cairo/CairoResource.cpp b/src/platform/graphics/cairo/CairoResource.cpp
index ee371efc..f8ce9666 100644
--- a/src/platform/graphics/cairo/CairoResource.cpp
+++ b/src/platform/graphics/cairo/CairoResource.cpp
@@ -2,14 +2,16 @@
#include "cru/platform/graphics/cairo/CairoGraphicsFactory.h"
namespace cru::platform::graphics::cairo {
-static const String kCairoGraphicsPlatformId(u"cairo");
+static const std::string kCairoGraphicsPlatformId("cairo");
CairoResource::CairoResource(CairoGraphicsFactory* factory)
: factory_(factory) {}
CairoResource::~CairoResource() {}
-String CairoResource::GetPlatformId() const { return kCairoGraphicsPlatformId; }
+std::string CairoResource::GetPlatformId() const {
+ return kCairoGraphicsPlatformId;
+}
IGraphicsFactory* CairoResource::GetGraphicsFactory() { return factory_; }
} // namespace cru::platform::graphics::cairo
diff --git a/src/platform/graphics/cairo/PangoFont.cpp b/src/platform/graphics/cairo/PangoFont.cpp
index d5c1ad0b..e375d674 100644
--- a/src/platform/graphics/cairo/PangoFont.cpp
+++ b/src/platform/graphics/cairo/PangoFont.cpp
@@ -1,23 +1,24 @@
#include "cru/platform/graphics/cairo/PangoFont.h"
namespace cru::platform::graphics::cairo {
-PangoFont::PangoFont(CairoGraphicsFactory* factory, String font_family,
+PangoFont::PangoFont(CairoGraphicsFactory* factory, std::string font_family,
float font_size)
: CairoResource(factory),
font_family_(std::move(font_family)),
font_size_(font_size) {
pango_font_description_ = pango_font_description_new();
- auto font_family_str = font_family_.ToUtf8();
+ auto font_family_str = font_family_;
pango_font_description_set_family(pango_font_description_,
font_family_str.c_str());
- pango_font_description_set_size(pango_font_description_, font_size * PANGO_SCALE);
+ pango_font_description_set_size(pango_font_description_,
+ font_size * PANGO_SCALE);
}
PangoFont::~PangoFont() {
pango_font_description_free(pango_font_description_);
}
-String PangoFont::GetFontName() { return font_family_; }
+std::string PangoFont::GetFontName() { return font_family_; }
float PangoFont::GetFontSize() { return font_size_; }
} // namespace cru::platform::graphics::cairo
diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp
index 746056e2..f8ed20c7 100644
--- a/src/platform/graphics/cairo/PangoTextLayout.cpp
+++ b/src/platform/graphics/cairo/PangoTextLayout.cpp
@@ -1,5 +1,4 @@
#include "cru/platform/graphics/cairo/PangoTextLayout.h"
-#include "cru/base/StringUtil.h"
#include "cru/platform/Check.h"
#include "cru/platform/GraphicsBase.h"
#include "cru/platform/graphics/Base.h"
@@ -24,7 +23,7 @@ PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory,
std::shared_ptr<IFont> font)
: CairoResource(factory) {
Expects(font);
- font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<PangoFont>(font, GetPlatformId());
pango_layout_ = pango_cairo_create_layout(factory->GetDefaultCairo());
pango_layout_set_font_description(pango_layout_,
font_->GetPangoFontDescription());
@@ -32,19 +31,18 @@ PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory,
PangoTextLayout::~PangoTextLayout() { g_object_unref(pango_layout_); }
-String PangoTextLayout::GetText() { return text_; }
+std::string PangoTextLayout::GetText() { return text_; }
-void PangoTextLayout::SetText(String new_text) {
+void PangoTextLayout::SetText(std::string new_text) {
text_ = std::move(new_text);
- utf8_text_ = text_.ToUtf8();
- pango_layout_set_text(pango_layout_, utf8_text_.c_str(), utf8_text_.size());
+ pango_layout_set_text(pango_layout_, text_.c_str(), text_.size());
}
std::shared_ptr<IFont> PangoTextLayout::GetFont() { return font_; }
void PangoTextLayout::SetFont(std::shared_ptr<IFont> font) {
Expects(font);
- font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<PangoFont>(font, GetPlatformId());
pango_layout_set_font_description(pango_layout_,
font_->GetPangoFontDescription());
}
@@ -63,9 +61,8 @@ void PangoTextLayout::SetEditMode(bool enable) { edit_mode_ = enable; }
Index PangoTextLayout::GetLineIndexFromCharIndex(Index char_index) {
int line;
- pango_layout_index_to_line_x(pango_layout_,
- FromUtf16IndexToUtf8Index(char_index), false,
- &line, nullptr);
+ pango_layout_index_to_line_x(pango_layout_, char_index, false, &line,
+ nullptr);
return line;
}
@@ -80,27 +77,6 @@ float PangoTextLayout::GetLineHeight(Index line_index) {
return static_cast<float>(height) / PANGO_SCALE;
}
-Index PangoTextLayout::FromUtf8IndexToUtf16Index(Index index) {
- Utf8CodePointIterator iter(utf8_text_.data(), utf8_text_.size());
- int cp_count = 0;
- while ((!iter.IsPastEnd()) && iter.GetPosition() < index) {
- ++iter;
- cp_count++;
- }
- return text_.IndexFromCodePointToCodeUnit(cp_count);
-}
-
-Index PangoTextLayout::FromUtf16IndexToUtf8Index(Index index) {
- Index cp_index = text_.IndexFromCodeUnitToCodePoint(index);
- Utf8CodePointIterator iter(utf8_text_.data(), utf8_text_.size());
-
- for (Index i = 0; i < cp_index; ++i) {
- ++iter;
- }
-
- return iter.GetPosition();
-}
-
Rect PangoTextLayout::GetTextBounds(bool includingTrailingSpace) {
PangoRectangle rectangle;
pango_layout_get_extents(pango_layout_, nullptr, &rectangle);
@@ -110,17 +86,17 @@ Rect PangoTextLayout::GetTextBounds(bool includingTrailingSpace) {
std::vector<Rect> PangoTextLayout::TextRangeRect(const TextRange& text_range) {
auto tr = text_range.Normalize();
- auto utf8_start_index = FromUtf16IndexToUtf8Index(tr.GetStart());
- auto utf8_end_index = FromUtf16IndexToUtf8Index(tr.GetEnd());
+ auto start_index = tr.GetStart();
+ auto end_index = tr.GetEnd();
PangoRectangle rectangle;
int start_line_index, end_line_index, start_x_pos, end_x_pos;
- pango_layout_index_to_line_x(pango_layout_, utf8_start_index, false,
+ pango_layout_index_to_line_x(pango_layout_, start_index, false,
&start_line_index, &start_x_pos);
- pango_layout_index_to_line_x(pango_layout_, utf8_end_index, false,
- &end_line_index, &end_x_pos);
+ pango_layout_index_to_line_x(pango_layout_, end_index, false, &end_line_index,
+ &end_x_pos);
- pango_layout_index_to_pos(pango_layout_, utf8_start_index, &rectangle);
+ pango_layout_index_to_pos(pango_layout_, start_index, &rectangle);
auto top = rectangle.y;
if (start_line_index == end_line_index) {
@@ -161,9 +137,8 @@ std::vector<Rect> PangoTextLayout::TextRangeRect(const TextRange& text_range) {
}
Rect PangoTextLayout::TextSinglePoint(Index position, bool trailing) {
- auto utf8_index = FromUtf16IndexToUtf8Index(position);
int line_index, x_pos, y_pos = 0;
- pango_layout_index_to_line_x(pango_layout_, utf8_index, trailing, &line_index,
+ pango_layout_index_to_line_x(pango_layout_, position, trailing, &line_index,
&x_pos);
for (int i = 0; i < line_index; i++) {
@@ -186,8 +161,7 @@ TextHitTestResult PangoTextLayout::HitTest(const Point& point) {
auto inside_text =
pango_layout_xy_to_index(pango_layout_, point.x * PANGO_SCALE,
point.y * PANGO_SCALE, &index, &trailing);
- return TextHitTestResult{FromUtf8IndexToUtf16Index(index), trailing != 0,
- inside_text != 0};
+ return TextHitTestResult{index, trailing != 0, inside_text != 0};
}
} // namespace cru::platform::graphics::cairo
diff --git a/src/platform/graphics/direct2d/ImageFactory.cpp b/src/platform/graphics/direct2d/ImageFactory.cpp
index b9e9221a..aff411c4 100644
--- a/src/platform/graphics/direct2d/ImageFactory.cpp
+++ b/src/platform/graphics/direct2d/ImageFactory.cpp
@@ -74,7 +74,7 @@ GUID ConvertImageFormatToGUID(ImageFormat format) {
void WinImageFactory::EncodeToStream(IImage* image, io::Stream* stream,
ImageFormat format, float quality) {
- auto direct_image = CheckPlatform<Direct2DImage>(image, GetPlatformIdUtf8());
+ auto direct_image = CheckPlatform<Direct2DImage>(image, GetPlatformId());
Microsoft::WRL::ComPtr<IStream> com_stream(
platform::win::ConvertStreamToComStream(stream));
diff --git a/src/platform/graphics/direct2d/Painter.cpp b/src/platform/graphics/direct2d/Painter.cpp
index 29ddcabb..fabcdafd 100644
--- a/src/platform/graphics/direct2d/Painter.cpp
+++ b/src/platform/graphics/direct2d/Painter.cpp
@@ -55,7 +55,7 @@ void D2DDeviceContextPainter::Clear(const Color& color) {
void D2DDeviceContextPainter::DrawLine(const Point& start, const Point& end,
IBrush* brush, float width) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawLine(Convert(start), Convert(end),
b->GetD2DBrushInterface(), width);
}
@@ -63,7 +63,7 @@ void D2DDeviceContextPainter::DrawLine(const Point& start, const Point& end,
void D2DDeviceContextPainter::StrokeRectangle(const Rect& rectangle,
IBrush* brush, float width) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawRectangle(Convert(rectangle), b->GetD2DBrushInterface(),
width);
}
@@ -71,14 +71,14 @@ void D2DDeviceContextPainter::StrokeRectangle(const Rect& rectangle,
void D2DDeviceContextPainter::FillRectangle(const Rect& rectangle,
IBrush* brush) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->FillRectangle(Convert(rectangle), b->GetD2DBrushInterface());
}
void D2DDeviceContextPainter::StrokeEllipse(const Rect& outline_rect,
IBrush* brush, float width) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawEllipse(
D2D1::Ellipse(Convert(outline_rect.GetCenter()),
outline_rect.width / 2.0f, outline_rect.height / 2.0f),
@@ -87,7 +87,7 @@ void D2DDeviceContextPainter::StrokeEllipse(const Rect& outline_rect,
void D2DDeviceContextPainter::FillEllipse(const Rect& outline_rect,
IBrush* brush) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->FillEllipse(
D2D1::Ellipse(Convert(outline_rect.GetCenter()),
outline_rect.width / 2.0f, outline_rect.height / 2.0f),
@@ -97,16 +97,16 @@ void D2DDeviceContextPainter::FillEllipse(const Rect& outline_rect,
void D2DDeviceContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
CheckValidation();
- const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformIdUtf8());
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformId());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawGeometry(g->GetComInterface(), b->GetD2DBrushInterface(),
width);
}
void D2DDeviceContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
CheckValidation();
- const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformIdUtf8());
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformId());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->FillGeometry(g->GetComInterface(),
b->GetD2DBrushInterface());
}
@@ -115,15 +115,15 @@ void D2DDeviceContextPainter::DrawText(const Point& offset,
ITextLayout* text_layout,
IBrush* brush) {
CheckValidation();
- const auto t = CheckPlatform<DWriteTextLayout>(text_layout, GetPlatformIdUtf8());
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto t = CheckPlatform<DWriteTextLayout>(text_layout, GetPlatformId());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawTextLayout(Convert(offset), t->GetComInterface(),
b->GetD2DBrushInterface());
}
void D2DDeviceContextPainter::DrawImage(const Point& offset, IImage* image) {
CheckValidation();
- const auto i = CheckPlatform<Direct2DImage>(image, GetPlatformIdUtf8());
+ const auto i = CheckPlatform<Direct2DImage>(image, GetPlatformId());
Microsoft::WRL::ComPtr<ID2D1DeviceContext> device_context;
diff --git a/src/platform/graphics/direct2d/TextLayout.cpp b/src/platform/graphics/direct2d/TextLayout.cpp
index 7a2074ec..06bbcaa6 100644
--- a/src/platform/graphics/direct2d/TextLayout.cpp
+++ b/src/platform/graphics/direct2d/TextLayout.cpp
@@ -14,7 +14,7 @@ DWriteTextLayout::DWriteTextLayout(DirectGraphicsFactory* factory,
std::shared_ptr<IFont> font, String text)
: DirectGraphicsResource(factory), text_(std::move(text)) {
Expects(font);
- font_ = CheckPlatform<DWriteFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<DWriteFont>(font, GetPlatformId());
ThrowIfFailed(factory->GetDWriteFactory()->CreateTextLayout(
reinterpret_cast<const wchar_t*>(text_.c_str()),
@@ -39,7 +39,7 @@ std::shared_ptr<IFont> DWriteTextLayout::GetFont() {
}
void DWriteTextLayout::SetFont(std::shared_ptr<IFont> font) {
- font_ = CheckPlatform<DWriteFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<DWriteFont>(font, GetPlatformId());
ThrowIfFailed(GetDirectFactory()->GetDWriteFactory()->CreateTextLayout(
reinterpret_cast<const wchar_t*>(text_.c_str()),
static_cast<UINT32>(text_.size()), font_->GetComInterface(), max_width_,
diff --git a/src/platform/graphics/quartz/Factory.cpp b/src/platform/graphics/quartz/Factory.cpp
index 5d5b48b5..862c0966 100644
--- a/src/platform/graphics/quartz/Factory.cpp
+++ b/src/platform/graphics/quartz/Factory.cpp
@@ -33,7 +33,7 @@ std::unique_ptr<IFont> QuartzGraphicsFactory::CreateFont(String font_family,
std::unique_ptr<ITextLayout> QuartzGraphicsFactory::CreateTextLayout(
std::shared_ptr<IFont> font, String text) {
- auto f = CheckPlatform<OsxCTFont>(font, GetPlatformIdUtf8());
+ auto f = CheckPlatform<OsxCTFont>(font, GetPlatformId());
return std::make_unique<OsxCTTextLayout>(this, f, text);
}
diff --git a/src/platform/graphics/quartz/ImageFactory.cpp b/src/platform/graphics/quartz/ImageFactory.cpp
index 62229bcb..2090828c 100644
--- a/src/platform/graphics/quartz/ImageFactory.cpp
+++ b/src/platform/graphics/quartz/ImageFactory.cpp
@@ -49,7 +49,7 @@ void QuartzImageFactory::EncodeToStream(IImage* image, io::Stream* stream,
throw Exception("Invalid quality value.");
}
- auto quartz_image = CheckPlatform<QuartzImage>(image, GetPlatformIdUtf8());
+ auto quartz_image = CheckPlatform<QuartzImage>(image, GetPlatformId());
auto cg_image = quartz_image->GetCGImage();
auto uti = ToCFString(GetImageFormatUniformTypeIdentifier(format));
diff --git a/src/platform/graphics/quartz/Painter.cpp b/src/platform/graphics/quartz/Painter.cpp
index fe0f5d43..45dee716 100644
--- a/src/platform/graphics/quartz/Painter.cpp
+++ b/src/platform/graphics/quartz/Painter.cpp
@@ -66,7 +66,7 @@ void QuartzCGContextPainter::DrawLine(const Point& start, const Point& end,
CGContextMoveToPoint(cg_context_, start.x, start.y);
CGContextAddLineToPoint(cg_context_, end.x, end.y);
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
SetLineWidth(width);
@@ -77,7 +77,7 @@ void QuartzCGContextPainter::StrokeRectangle(const Rect& rectangle,
IBrush* brush, float width) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextStrokeRectWithWidth(cg_context_, Convert(rectangle), width);
}
@@ -86,7 +86,7 @@ void QuartzCGContextPainter::FillRectangle(const Rect& rectangle,
IBrush* brush) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextFillRect(cg_context_, Convert(rectangle));
}
@@ -95,7 +95,7 @@ void QuartzCGContextPainter::StrokeEllipse(const Rect& outline_rect,
IBrush* brush, float width) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
SetLineWidth(width);
@@ -106,7 +106,7 @@ void QuartzCGContextPainter::FillEllipse(const Rect& outline_rect,
IBrush* brush) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextFillEllipseInRect(cg_context_, Convert(outline_rect));
}
@@ -115,8 +115,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
Validate();
- QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformIdUtf8());
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
SetLineWidth(width);
@@ -129,8 +129,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
void QuartzCGContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
Validate();
- QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformIdUtf8());
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextBeginPath(cg_context_);
@@ -142,7 +142,7 @@ void QuartzCGContextPainter::DrawText(const Point& offset,
ITextLayout* text_layout, IBrush* brush) {
Validate();
- auto tl = CheckPlatform<OsxCTTextLayout>(text_layout, GetPlatformIdUtf8());
+ auto tl = CheckPlatform<OsxCTTextLayout>(text_layout, GetPlatformId());
Color color;
@@ -169,7 +169,7 @@ void QuartzCGContextPainter::DrawText(const Point& offset,
void QuartzCGContextPainter::DrawImage(const Point& offset, IImage* image) {
Validate();
- auto i = CheckPlatform<QuartzImage>(image, GetPlatformIdUtf8());
+ auto i = CheckPlatform<QuartzImage>(image, GetPlatformId());
auto cg_image = i->GetCGImage();
diff --git a/src/platform/graphics/quartz/TextLayout.cpp b/src/platform/graphics/quartz/TextLayout.cpp
index 41a2f176..8c573c7a 100644
--- a/src/platform/graphics/quartz/TextLayout.cpp
+++ b/src/platform/graphics/quartz/TextLayout.cpp
@@ -31,7 +31,7 @@ OsxCTTextLayout::~OsxCTTextLayout() {
}
void OsxCTTextLayout::SetFont(std::shared_ptr<IFont> font) {
- font_ = CheckPlatform<OsxCTFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<OsxCTFont>(font, GetPlatformId());
RecreateFrame();
}
diff --git a/src/platform/graphics/web_canvas/Painter.cpp b/src/platform/graphics/web_canvas/Painter.cpp
index f928de35..c9184165 100644
--- a/src/platform/graphics/web_canvas/Painter.cpp
+++ b/src/platform/graphics/web_canvas/Painter.cpp
@@ -94,7 +94,7 @@ void WebCanvasPainter::SetFillStyle(IBrush* brush) {
}
WebCanvasBrush* WebCanvasPainter::ConvertBrush(IBrush* brush) const {
- return CheckPlatform<WebCanvasBrush>(brush, GetPlatformIdUtf8());
+ return CheckPlatform<WebCanvasBrush>(brush, GetPlatformId());
}
WebCanvasRef WebCanvasPainter::GetCanvas() {