Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,9 @@ player_find_package(NAME fmt TARGET fmt::fmt VERSION 5.2 REQUIRED)
find_package(Pixman REQUIRED)
target_link_libraries(${PROJECT_NAME} PIXMAN::PIXMAN)

find_package(ICU COMPONENTS i18n uc data REQUIRED)
target_link_libraries(${PROJECT_NAME} ICU::i18n ICU::uc ICU::data)

# Always enable Wine registry support on non-Windows, but not for console ports
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows"
AND NOT PLAYER_CONSOLE_PORT)
Expand Down
10 changes: 6 additions & 4 deletions src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "system.h"
#include "game_system.h"
#include "main_data.h"
#include "text.h"

#ifdef HAVE_FREETYPE
#ifndef __PS4__
Expand Down Expand Up @@ -157,7 +158,7 @@ namespace {
GlyphRet vRenderShaped(char32_t glyph) const override;
bool vCanShape() const override;
#ifdef HAVE_HARFBUZZ
std::vector<ShapeRet> vShape(std::u32string_view txt) const override;
std::vector<ShapeRet> vShape(std::u32string_view txt, Text::Direction direction) const override;
#endif
void vApplyStyle(const Style& style) override;

Expand Down Expand Up @@ -506,11 +507,12 @@ bool FTFont::vCanShape() const {
}

#ifdef HAVE_HARFBUZZ
std::vector<Font::ShapeRet> FTFont::vShape(std::u32string_view txt) const {
std::vector<Font::ShapeRet> FTFont::vShape(std::u32string_view txt, Text::Direction direction) const {
hb_buffer_clear_contents(hb_buffer);

hb_buffer_add_utf32(hb_buffer, reinterpret_cast<const uint32_t*>(txt.data()), txt.size(), 0, txt.size());
hb_buffer_guess_segment_properties(hb_buffer);
hb_buffer_set_direction(hb_buffer, direction == Text::Direction::LTR ? HB_DIRECTION_LTR : HB_DIRECTION_RTL);

hb_shape(hb_font, hb_buffer, nullptr, 0);

Expand Down Expand Up @@ -899,10 +901,10 @@ bool Font::CanShape() const {
return vCanShape();
}

std::vector<Font::ShapeRet> Font::Shape(std::u32string_view text) const {
std::vector<Font::ShapeRet> Font::Shape(std::u32string_view text, Text::Direction direction) const {
assert(vCanShape());

return vShape(text);
return vShape(text, direction);
}

void Font::SetFallbackFont(FontRef fallback_font) {
Expand Down
5 changes: 3 additions & 2 deletions src/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "memory_management.h"
#include "rect.h"
#include "string_view.h"
#include "text.h"
#include <string>
#include <lcf/scope_guard.h>

Expand Down Expand Up @@ -185,7 +186,7 @@ class Font {
* @param text Text to shape
* @return Shaping information. See Font::ShapeRet
*/
std::vector<ShapeRet> Shape(std::u32string_view text) const;
std::vector<ShapeRet> Shape(std::u32string_view text, Text::Direction direction) const;

/**
* Defines a fallback font that shall be used when a glyph is not found in the current font.
Expand Down Expand Up @@ -251,7 +252,7 @@ class Font {
virtual GlyphRet vRender(char32_t glyph) const = 0;
virtual GlyphRet vRenderShaped(char32_t glyph) const { return vRender(glyph); };
virtual bool vCanShape() const { return false; }
virtual std::vector<ShapeRet> vShape(std::u32string_view) const { return {}; }
virtual std::vector<ShapeRet> vShape(std::u32string_view, Text::Direction) const { return {}; }
virtual void vApplyStyle(const Style& style) { (void)style; };

protected:
Expand Down
5 changes: 4 additions & 1 deletion src/pending_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "game_switches.h"
#include <lcf/data.h>
#include "output.h"
#include "text.h"
#include "utils.h"
#include "player.h"
#include "main_data.h"
Expand All @@ -46,6 +47,7 @@ int PendingMessage::PushLineImpl(std::string msg) {
RemoveControlChars(msg);
msg = ApplyTextInsertingCommands(std::move(msg), Player::escape_char, command_inserter);
texts.push_back(std::move(msg));
runs.push_back(Text::Bidi(texts.back(), Text::Direction::LTR));
return texts.size();
}

Expand Down Expand Up @@ -75,6 +77,7 @@ int PendingMessage::PushNumInput(int variable_id, int num_digits) {
void PendingMessage::PushPageEnd() {
assert(!HasChoices());
assert(!HasNumberInput());
// FIXME: Runs
if (texts.empty()) {
texts.push_back("");
}
Expand Down Expand Up @@ -132,7 +135,7 @@ std::string PendingMessage::ApplyTextInsertingCommands(std::string input, uint32
if (fn_res) {
output.append(*fn_res);
start_copy = iter;
}
}
}

if (start_copy == input.data()) {
Expand Down
4 changes: 4 additions & 0 deletions src/pending_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

#ifndef EP_PENDING_MESSAGE_H
#define EP_PENDING_MESSAGE_H

#include <cstdint>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
#include <optional>
#include "async_op.h"
#include "text.h"

class PendingMessage {
public:
Expand All @@ -44,6 +46,7 @@ class PendingMessage {
void SetChoiceContinuation(ChoiceContinuation f) { choice_continuation = std::move(f); }

const std::vector<std::string>& GetLines() const { return texts; }
const std::vector<std::vector<Text::Run>>& GetRuns() const { return runs; }

bool IsActive() const { return NumLines() || HasNumberInput(); }
int NumLines() const { return texts.size(); }
Expand Down Expand Up @@ -78,6 +81,7 @@ class PendingMessage {
CommandInserter command_inserter;
ChoiceContinuation choice_continuation;
std::vector<std::string> texts;
std::vector<std::vector<Text::Run>> runs;
int choice_start = -1;
int choice_cancel_type = 5;
int num_input_variable = 0;
Expand Down
9 changes: 9 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "scene_settings.h"
#include "scene_title.h"
#include "instrumentation.h"
#include "translation.h"
#include "transition.h"
#include <lcf/scope_guard.h>
#include <lcf/log_handler.h>
Expand Down Expand Up @@ -1628,6 +1629,14 @@ bool Player::IsCP1251() {
return (encoding == "ibm-5347_P100-1998" || encoding == "windows-1251" || encoding == "1251");
}

bool Player::IsRTL() {
if (Tr::HasActiveTranslation() && !Tr::GetCurrentLanguageCode().empty()) {
return Tr::GetCurrentLanguageCode() == "ar_AR" || Tr::GetCurrentLanguageCode() == "he_IL";
}

return false;
}

int Player::EngineVersion() {
if (IsRPG2k3()) return 2003;
if (IsRPG2k()) return 2000;
Expand Down
5 changes: 5 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ namespace Player {
*/
bool IsCP1251();

/**
* @return true when the active language is right-to-left like Arabic or Hebrew.
*/
bool IsRTL();

/** @return true when engine is 2k3 or the 2k3-commands patch is enabled */
bool IsRPG2k3Commands();

Expand Down
3 changes: 3 additions & 0 deletions src/scene_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ void Scene_Menu::Start() {

// Gold Window
gold_window.reset(new Window_Gold(Player::menu_offset_x, (Player::screen_height - gold_window_height - Player::menu_offset_y), gold_window_width, gold_window_height));
gold_window->ApplyRtlMirror();

// Status Window
menustatus_window.reset(new Window_MenuStatus(Player::menu_offset_x + menu_command_width, Player::menu_offset_y, (MENU_WIDTH - menu_command_width), MENU_HEIGHT));
menustatus_window->SetActive(false);
menustatus_window->ApplyRtlMirror();
}

void Scene_Menu::Continue(SceneType /* prev_scene */) {
Expand Down Expand Up @@ -161,6 +163,7 @@ void Scene_Menu::CreateCommandWindow() {
command_window.reset(new Window_Command(options, menu_command_width));
command_window->SetX(Player::menu_offset_x);
command_window->SetY(Player::menu_offset_y);
command_window->ApplyRtlMirror();
command_window->SetIndex(menu_index);

// Disable items
Expand Down
Loading
Loading