Skip to content

Commit

Permalink
Add new TextBlob class and text_shape example
Browse files Browse the repository at this point in the history
Now we have TextBlob::Make() and TextBlob::MakeWithShaper() to
cache/store the shaped layout of a set of glyphs to be rendered with
draw_text(..., TextBlobRef, ...). We can also iterate clusters with
RunHandler.

There is still some work to be done for RTL text and composed
chars. And we should try to replace the old DrawTextDelegate with the
new TextBlob::RunHandler in the future.
  • Loading branch information
dacap committed Feb 23, 2024
1 parent c788600 commit 529dc9d
Show file tree
Hide file tree
Showing 23 changed files with 727 additions and 100 deletions.
2 changes: 1 addition & 1 deletion cmake/FindSkia.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,6 @@ add_library(skunicode INTERFACE)
target_link_libraries(skunicode INTERFACE ${SKUNICODE_LIBRARY})

add_library(skshaper INTERFACE)
target_link_libraries(skshaper INTERFACE ${SKSHAPER_LIBRARY})
target_link_libraries(skshaper INTERFACE ${SKSHAPER_LIBRARY} skunicode)
target_compile_definitions(skshaper INTERFACE
SK_SHAPER_HARFBUZZ_AVAILABLE)
25 changes: 13 additions & 12 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# LAF OS
# Copyright (C) 2019-2024 Igara Studio S.A.

if(LAF_BACKEND STREQUAL "skia")
function(laf_add_example name console="")
if("${console}" STREQUAL "CONSOLE")
add_executable(${name} ${name}.cpp)
else()
add_executable(${name} WIN32 ${name}.cpp)
endif()
target_link_libraries(${name} laf-os laf-text)
set_target_properties(${name} PROPERTIES LINK_FLAGS "${LAF_BACKEND_LINK_FLAGS}")
endfunction()
function(laf_add_example name console="")
if("${console}" STREQUAL "CONSOLE")
add_executable(${name} ${name}.cpp)
else()
add_executable(${name} WIN32 ${name}.cpp)
endif()
target_link_libraries(${name} laf-os laf-text)
set_target_properties(${name} PROPERTIES LINK_FLAGS "${LAF_BACKEND_LINK_FLAGS}")
endfunction()

laf_add_example(base64 CONSOLE)
laf_add_example(show_platform CONSOLE)
if(LAF_BACKEND STREQUAL "skia")
laf_add_example(allevents GUI)
laf_add_example(base64 CONSOLE)
laf_add_example(complextextlayout GUI)
laf_add_example(custom_window GUI)
laf_add_example(floating_window GUI)
Expand All @@ -23,5 +24,5 @@ if(LAF_BACKEND STREQUAL "skia")
laf_add_example(multiple_windows GUI)
laf_add_example(panviewport GUI)
laf_add_example(shader GUI)
laf_add_example(show_platform CONSOLE)
laf_add_example(text_shape GUI)
endif()
8 changes: 2 additions & 6 deletions examples/complextextlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void draw_window(Window* window,
"👍❤️😂☺️😯😢😡" }; // Emojis

MyDrawTextDelegate delegate(mousePos);
gfx::Point pos(0, 0);
gfx::PointF pos(0, 0);
for (auto line : lines) {
std::string s = line;
draw_text_with_shaper(
Expand Down Expand Up @@ -110,13 +110,9 @@ int app_main(int argc, char* argv[])
redraw = false;
draw_window(window.get(), fontMgr, font, mousePos);
}
// Wait for an event in the queue, the "true" parameter indicates
// that we'll wait for a new event, and the next line will not be
// processed until we receive a new event. If we use "false" and
// there is no events in the queue, we receive an "ev.type() == Event::None

Event ev;
queue->getEvent(ev);

switch (ev.type()) {

case Event::CloseWindow:
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void draw_window(Window* window,

p.color(kTitleBarText);
draw_text(surface, nullptr, "Custom Window",
rc2.center(), &p, TextAlign::Center);
rc2.center(), &p, TextAlign::Center);

// Draw buttons
draw_button(surface, rc.x2()-kButtonSize, Hit::CloseButton, hit);
Expand All @@ -151,13 +151,13 @@ void draw_window(Window* window,
p.style(Paint::Style::Fill);
p.color(kContentText);
draw_text(surface, font, "Content Rect",
rc2.center(), &p, TextAlign::Center);
rc2.center(), &p, TextAlign::Center);

if (window->isFullscreen()) {
auto pos = rc2.center();
pos.y += 24;
draw_text(surface, font, "(F key or F11 to exit full screen)",
pos, &p, TextAlign::Center);
pos, &p, TextAlign::Center);
}

if (window->isVisible())
Expand Down
Loading

0 comments on commit 529dc9d

Please sign in to comment.