Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New text tool #4383

Draft
wants to merge 9 commits into
base: beta
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ To compile Aseprite you will need:

* The latest version of [CMake](https://cmake.org) (3.16 or greater)
* [Ninja](https://ninja-build.org) build system
* And a compiled version of the `aseprite-m102` branch of
* And a compiled version of the `aseprite-m124` branch of
the [Skia library](https://github.com/aseprite/skia#readme).
There are [pre-built packages available](https://github.com/aseprite/skia/releases).
You can get some extra information in
Expand Down Expand Up @@ -190,7 +190,7 @@ but it could be different in your Mac.
### Apple Silicon

If you running macOS on an ARM64/AArch64/Apple Silicon Mac (e.g. M1),
you can compile a native ARM64 version of Aseprite following similar
you can compile a native ARM64 version of Aseprite following similar
steps as above but when we call `cmake`, we have some differences:

cd aseprite
Expand Down
Binary file modified data/extensions/aseprite-theme/dark/sheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/extensions/aseprite-theme/dark/theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
<part id="tool_filled_ellipse" x="192" y="80" w="16" h="16" />
<part id="tool_contour" x="144" y="96" w="16" h="16" />
<part id="tool_polygon" x="160" y="96" w="16" h="16" />
<part id="tool_text" x="144" y="112" w="16" h="16" />
<part id="tool_blur" x="160" y="112" w="16" h="16" />
<part id="tool_jumble" x="176" y="112" w="16" h="16" />
<part id="tool_configuration" x="144" y="128" w="16" h="16" />
Expand Down
Binary file modified data/extensions/aseprite-theme/sheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/extensions/aseprite-theme/theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
<part id="tool_filled_ellipse" x="192" y="80" w="16" h="16" />
<part id="tool_contour" x="144" y="96" w="16" h="16" />
<part id="tool_polygon" x="160" y="96" w="16" h="16" />
<part id="tool_text" x="144" y="112" w="16" h="16" />
<part id="tool_blur" x="160" y="112" w="16" h="16" />
<part id="tool_jumble" x="176" y="112" w="16" h="16" />
<part id="tool_configuration" x="144" y="128" w="16" h="16" />
Expand Down
13 changes: 12 additions & 1 deletion data/gui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
<key command="Outline" shortcut="Shift+O" />
<key command="ColorCurve" shortcut="Ctrl+M" />
<key command="ColorCurve" shortcut="F10" />
<key command="PasteText" shortcut="T" />
<key command="Options" mac="Cmd+," />
<key command="Options" shortcut="Ctrl+K" mac="Cmd+K" />
<key command="KeyboardShortcuts" shortcut="Ctrl+Alt+Shift+K" mac="Cmd+Alt+Shift+K" />
Expand Down Expand Up @@ -611,6 +610,8 @@

<key tool="blur" shortcut="R" />
<key tool="jumble" shortcut="R" />

<key tool="text" shortcut="T" />
</tools>

<!-- Editor Quicktools: these are modifiers to select quickly a
Expand Down Expand Up @@ -1493,6 +1494,16 @@
default_brush_size="16" />
</group>

<group id="text">
<tool id="text"
text="@.text"
ink="text"
controller="two_points"
pointshape="pixel"
intertwine="as_rectangles"
traceepolicy="last" />
</group>

</tools>

</gui>
1 change: 1 addition & 0 deletions data/pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
<option id="font_face" type="std::string" />
<option id="font_size" type="int" default="12" />
<option id="antialias" type="bool" default="false" />
<option id="font_info" type="std::string" />
</section>
<section id="symmetry_mode">
<option id="enabled" type="bool" default="false" />
Expand Down
7 changes: 5 additions & 2 deletions data/strings/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,10 @@ preview = &Preview
tiled = &Tiled

[font_popup]
title = Fonts
load = Load
theme_fonts = Theme Fonts
system_fonts = System Fonts
load = Load External Font
select_truetype_fonts = Select a Font File
empty_fonts = No system fonts were found

[frame_combo]
Expand Down Expand Up @@ -1807,6 +1809,7 @@ contour = Contour Tool
polygon = Polygon Tool
blur = Blur Tool
jumble = Jumble Tool
text = Text Tool
shortcut = Shortcut: {0}
preview_hide = Hide Preview
preview_show = Show Preview
Expand Down
4 changes: 2 additions & 2 deletions data/widgets/font_popup.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!-- Aseprite -->
<!-- Copyright (C) 2024 by Igara Studio S.A. -->
<!-- Copyright (C) 2015-2017 by David Capello -->
<gui>
<vbox id="font_popup">
<search id="search" magnet="true" />
<view id="view" expansive="true" />
<hbox>
<boxfiller />
<button id="load_font" text="@.load" magnet="true" minwidth="80" />
<button id="load_font" text="@.load" minwidth="80" />
</hbox>
</vbox>
</gui>
17 changes: 6 additions & 11 deletions data/widgets/paste_text.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
<!-- Aseprite -->
<!-- Copyright (C) 2024 by Igara Studio S.A. -->
<!-- Copyright (C) 2015-2018 by David Capello -->
<gui>
<window id="paste_text" text="@.title">
<grid columns="2">
<label text="@.text" />
<entry expansive="true" maxsize="256" id="user_text" magnet="true" cell_align="horizontal" />

<label text="@.font_size" />
<expr id="font_size" text="32" cell_align="horizontal" />
<entry expansive="true" maxsize="256" minwidth="256" id="user_text" magnet="true" cell_align="horizontal" />

<label text="@.font" />
<dropdownbutton minwidth="60" id="font_face" text="@.select_font" cell_align="horizontal" />
<font id="font_face" cell_align="horizontal" />

<label text="@.color" />
<colorpicker id="font_color" cell_align="horizontal" />

<hbox />
<check id="antialias"
text="@.antialias" cell_align="horizontal"
tooltip="@.antialias_tooltip" />
<hbox>
<colorpicker id="font_color" />
</hbox>

<separator horizontal="true" cell_hspan="2" />

Expand Down
7 changes: 5 additions & 2 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,19 @@ if(ENABLE_UI)
ui/editor/play_state.cpp
ui/editor/scrolling_state.cpp
ui/editor/select_box_state.cpp
ui/editor/select_text_box_state.cpp
ui/editor/standby_state.cpp
ui/editor/state_with_wheel_behavior.cpp
ui/editor/transform_handles.cpp
ui/editor/writing_text_state.cpp
ui/editor/zooming_state.cpp
ui/export_file_window.cpp
ui/expr_entry.cpp
ui/file_list.cpp
ui/file_list_view.cpp
ui/file_selector.cpp
ui/filename_field.cpp
ui/font_entry.cpp
ui/font_popup.cpp
ui/hex_color_entry.cpp
ui/home_view.cpp
Expand Down Expand Up @@ -660,6 +663,7 @@ target_sources(app-lib PRIVATE
file_system.cpp
filename_formatter.cpp
flatten.cpp
font_info.cpp
font_path.cpp
gui_xml.cpp
i18n/strings.cpp
Expand Down Expand Up @@ -709,7 +713,6 @@ target_sources(app-lib PRIVATE
util/conversion_to_surface.cpp
util/expand_cel_canvas.cpp
util/filetoks.cpp
util/freetype_utils.cpp
util/layer_boundaries.cpp
util/layer_utils.cpp
util/msk_file.cpp
Expand All @@ -719,6 +722,7 @@ target_sources(app-lib PRIVATE
util/pixel_ratio.cpp
util/range_utils.cpp
util/readable_time.cpp
util/render_text.cpp
util/resize_image.cpp
util/shader_helpers.cpp
util/tile_flags_utils.cpp
Expand All @@ -743,7 +747,6 @@ target_link_libraries(app-lib
tga-lib
laf-gfx
render-lib
laf-ft
laf-os
laf-text
ui-lib
Expand Down
114 changes: 19 additions & 95 deletions src/app/commands/cmd_paste_text.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -13,13 +13,11 @@
#include "app/commands/command.h"
#include "app/console.h"
#include "app/context.h"
#include "app/file_selector.h"
#include "app/pref/preferences.h"
#include "app/ui/drop_down_button.h"
#include "app/ui/editor/editor.h"
#include "app/ui/font_popup.h"
#include "app/ui/timeline/timeline.h"
#include "app/util/freetype_utils.h"
#include "app/util/render_text.h"
#include "base/fs.h"
#include "base/string.h"
#include "doc/image.h"
Expand Down Expand Up @@ -57,84 +55,16 @@ bool PasteTextCommand::onEnabled(Context* ctx)

class PasteTextWindow : public app::gen::PasteText {
public:
PasteTextWindow(const std::string& face, int size,
bool antialias,
const app::Color& color)
: m_face(face) {
ok()->setEnabled(!m_face.empty());
if (!m_face.empty())
updateFontFaceButton();

fontSize()->setTextf("%d", size);
fontFace()->Click.connect([this]{ onSelectFontFile(); });
fontFace()->DropDownClick.connect([this]{ onSelectSystemFont(); });
PasteTextWindow(const FontInfo& fontInfo,
const app::Color& color) {
fontFace()->setInfo(fontInfo);
fontColor()->setColor(color);
this->antialias()->setSelected(antialias);
}

std::string faceValue() const {
return m_face;
FontInfo fontInfo() const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'fontInfo' can be made static [readability-convert-member-functions-to-static]

Suggested change
FontInfo fontInfo() const {
static FontInfo fontInfo() {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug in clang-tidy.

return fontFace()->info();
}

int sizeValue() const {
int size = fontSize()->textInt();
size = std::clamp(size, 1, 5000);
return size;
}

private:
void updateFontFaceButton() {
fontFace()->mainButton()
->setTextf("Select Font: %s",
base::get_file_title(m_face).c_str());
}

void onSelectFontFile() {
base::paths exts = { "ttf", "ttc", "otf", "dfont" };
base::paths face;
if (!show_file_selector(
"Select a TrueType Font",
m_face, exts,
FileSelectorType::Open, face))
return;

ASSERT(!face.empty());
setFontFace(face.front());
}

void setFontFace(const std::string& face) {
m_face = face;
ok()->setEnabled(true);
updateFontFaceButton();
}

void onSelectSystemFont() {
if (!m_fontPopup) {
try {
m_fontPopup.reset(new FontPopup());
m_fontPopup->Load.connect(&PasteTextWindow::setFontFace, this);
m_fontPopup->Close.connect([this]{ onCloseFontPopup(); });
}
catch (const std::exception& ex) {
Console::showException(ex);
return;
}
}

if (!m_fontPopup->isVisible()) {
m_fontPopup->showPopup(display(), fontFace()->bounds());
}
else {
m_fontPopup->closeWindow(NULL);
}
}

void onCloseFontPopup() {
fontFace()->dropDown()->requestFocus();
}

std::string m_face;
std::unique_ptr<FontPopup> m_fontPopup;
};

void PasteTextCommand::onExecute(Context* ctx)
Expand All @@ -144,10 +74,8 @@ void PasteTextCommand::onExecute(Context* ctx)
return;

Preferences& pref = Preferences::instance();
PasteTextWindow window(pref.textTool.fontFace(),
pref.textTool.fontSize(),
pref.textTool.antialias(),
pref.colorBar.fgColor());
FontInfo fontInfo = FontInfo::getFromPreferences();
PasteTextWindow window(fontInfo, pref.colorBar.fgColor());

window.userText()->setText(last_text_used);

Expand All @@ -157,23 +85,19 @@ void PasteTextCommand::onExecute(Context* ctx)

last_text_used = window.userText()->text();

bool antialias = window.antialias()->isSelected();
std::string faceName = window.faceValue();
int size = window.sizeValue();
size = std::clamp(size, 1, 999);
pref.textTool.fontFace(faceName);
pref.textTool.fontSize(size);
pref.textTool.antialias(antialias);
fontInfo = window.fontInfo();
fontInfo.updatePreferences();

try {
std::string text = window.userText()->text();
app::Color appColor = window.fontColor()->getColor();
doc::color_t color = doc::rgba(appColor.getRed(),
appColor.getGreen(),
appColor.getBlue(),
appColor.getAlpha());

doc::ImageRef image(render_text(faceName, size, text, color, antialias));
app::Color color = window.fontColor()->getColor();

doc::ImageRef image = render_text(
fontInfo, text,
gfx::rgba(color.getRed(),
color.getGreen(),
color.getBlue(),
color.getAlpha()));
if (image) {
Sprite* sprite = editor->sprite();
if (image->pixelFormat() != sprite->pixelFormat()) {
Expand Down
Loading
Loading