aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-06-02 20:48:07 +0800
committercrupest <crupest@outlook.com>2022-06-02 20:48:07 +0800
commit4b90152f16dccf271188777dfabb99e97745732d (patch)
treeda7e54e41fc9add398734b6569fb7ef44081f33f
parent190487aec26f8c64ae488cc7bfb0ee068c7ddbb6 (diff)
downloadcru-4b90152f16dccf271188777dfabb99e97745732d.tar.gz
cru-4b90152f16dccf271188777dfabb99e97745732d.tar.bz2
cru-4b90152f16dccf271188777dfabb99e97745732d.zip
...
-rw-r--r--include/cru/platform/graphics/cairo/CairoGraphicsFactory.h3
-rw-r--r--include/cru/platform/graphics/cairo/PangoTextLayout.h38
-rw-r--r--src/platform/graphics/cairo/CMakeLists.txt8
-rw-r--r--src/platform/graphics/cairo/PangoTextLayout.cpp9
4 files changed, 57 insertions, 1 deletions
diff --git a/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h b/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h
index 130c1c26..280ea15f 100644
--- a/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h
+++ b/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h
@@ -4,6 +4,7 @@
#include "CairoResource.h"
#include <cairo/cairo.h>
+#include <pango/pango.h>
namespace cru::platform::graphics::cairo {
class CRU_PLATFORM_GRAPHICS_CAIRO_API CairoGraphicsFactory
@@ -20,5 +21,7 @@ class CRU_PLATFORM_GRAPHICS_CAIRO_API CairoGraphicsFactory
private:
cairo_surface_t* default_cairo_surface_;
cairo_t* default_cairo_;
+
+ PangoContext* pango_context_;
};
} // namespace cru::platform::graphics::cairo
diff --git a/include/cru/platform/graphics/cairo/PangoTextLayout.h b/include/cru/platform/graphics/cairo/PangoTextLayout.h
new file mode 100644
index 00000000..992e5b4a
--- /dev/null
+++ b/include/cru/platform/graphics/cairo/PangoTextLayout.h
@@ -0,0 +1,38 @@
+#pragma once
+#include "../TextLayout.h"
+#include "CairoResource.h"
+
+namespace cru::platform::graphics::cairo {
+class PangoTextLayout : public CairoResource, public virtual ITextLayout {
+ public:
+ explicit PangoTextLayout(CairoGraphicsFactory* factory);
+
+ ~PangoTextLayout() override;
+
+ public:
+ String GetText() override;
+ void SetText(String new_text) override;
+
+ std::shared_ptr<IFont> GetFont() override;
+ void SetFont(std::shared_ptr<IFont> font) override;
+
+ void SetMaxWidth(float max_width) override;
+ void SetMaxHeight(float max_height) override;
+
+ bool IsEditMode() override;
+ void SetEditMode(bool enable) override;
+
+ Index GetLineIndexFromCharIndex(Index char_index) override;
+ Index GetLineCount() override;
+ float GetLineHeight(Index line_index) override;
+
+ Rect GetTextBounds(bool includingTrailingSpace = false) override;
+ std::vector<Rect> TextRangeRect(const TextRange& text_range) override;
+ // Width is always 0, height is line height.
+ Rect TextSinglePoint(Index position, bool trailing) override;
+ TextHitTestResult HitTest(const Point& point) override;
+
+ private:
+ String text_;
+};
+} // namespace cru::platform::graphics::cairo
diff --git a/src/platform/graphics/cairo/CMakeLists.txt b/src/platform/graphics/cairo/CMakeLists.txt
index a9b78aac..addf07c9 100644
--- a/src/platform/graphics/cairo/CMakeLists.txt
+++ b/src/platform/graphics/cairo/CMakeLists.txt
@@ -1,7 +1,11 @@
if (UNIX)
find_library(LIB_CAIRO cairo REQUIRED)
find_library(LIB_PANGO NAMES pango pango-1.0 REQUIRED)
-
+ find_path(GLIB_HEADER_DIR NAMES glib.h PATH_SUFFIXES glib glib-2.0 REQUIRED)
+ find_path(GLIBCONFIG_HEADER_DIR NAMES glibconfig.h HINTS /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE} PATH_SUFFIXES glib glib/include glib-2.0 glib-2.0/include REQUIRED)
+ find_path(HARFBUZZ_HEADER_DIR NAMES hb.h PATH_SUFFIXES harfbuzz REQUIRED)
+ find_path(PANGO_HEADER_DIR NAMES pango PATH_SUFFIXES pango-1.0 REQUIRED)
+
add_library(CruPlatformGraphicsCairo SHARED
Base.cpp
CairoBrush.cpp
@@ -9,7 +13,9 @@ if (UNIX)
CairoGraphicsFactory.cpp
CairoResource.cpp
PangoFont.cpp
+ PangoTextLayout.cpp
)
target_compile_definitions(CruPlatformGraphicsCairo PRIVATE CRU_PLATFORM_GRAPHICS_CAIRO_EXPORT_API)
target_link_libraries(CruPlatformGraphicsCairo PUBLIC CruPlatformGraphics PUBLIC ${LIB_CAIRO} ${LIB_PANGO})
+ target_include_directories(CruPlatformGraphicsCairo PUBLIC ${GLIB_HEADER_DIR} ${GLIBCONFIG_HEADER_DIR} ${HARFBUZZ_HEADER_DIR} ${PANGO_HEADER_DIR})
endif()
diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp
new file mode 100644
index 00000000..65f2130e
--- /dev/null
+++ b/src/platform/graphics/cairo/PangoTextLayout.cpp
@@ -0,0 +1,9 @@
+#include "cru/platform/graphics/cairo/PangoTextLayout.h"
+
+namespace cru::platform::graphics::cairo {
+PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory)
+ : CairoResource(factory) {}
+
+PangoTextLayout::~PangoTextLayout() {}
+
+} // namespace cru::platform::graphics::cairo