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 8 commits into
base: beta
Choose a base branch
from
Draft

New text tool #4383

wants to merge 8 commits into from

Conversation

dacap
Copy link
Member

@dacap dacap commented Mar 25, 2024

A work-in-progress to convert the "insert text" command into an interactive "text tool."

This was linked to issues Mar 25, 2024
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

}

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.

src/app/font_info.cpp Outdated Show resolved Hide resolved
src/app/font_info_tests.cpp Outdated Show resolved Hide resolved
src/app/ui/font_entry.cpp Outdated Show resolved Hide resolved
case kFocusEnterMessage:
if (!m_popup) {
try {
FontInfo info = static_cast<FontEntry*>(parent())->info();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'info' of type 'FontInfo' can be declared 'const' [misc-const-correctness]

Suggested change
FontInfo info = static_cast<FontEntry*>(parent())->info();
FontInfo const info = static_cast<FontEntry*>(parent())->info();

font->setSize(fontInfo.size());
}
else {
const int size = (fontInfo.useDefaultSize() ? 18: fontInfo.size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

    const int size = (fontInfo.useDefaultSize() ? 18: fontInfo.size());
                     ^

if (bounds.w < 1) bounds.w = 1;
if (bounds.h < 1) bounds.h = 1;

image.reset(doc::Image::create(doc::IMAGE_RGB, bounds.w, bounds.h));
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

  image.reset(doc::Image::create(doc::IMAGE_RGB, bounds.w, bounds.h));
                                                 ^

if (bounds.w < 1) bounds.w = 1;
if (bounds.h < 1) bounds.h = 1;

image.reset(doc::Image::create(doc::IMAGE_RGB, bounds.w, bounds.h));
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

  image.reset(doc::Image::create(doc::IMAGE_RGB, bounds.w, bounds.h));
                                                           ^

src/ui/manager.cpp Outdated Show resolved Hide resolved
src/ui/manager.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions


for (int i=0; i<info.glyphCount; ++i) {
auto rc = info.getGlyphBounds(i);
m_bounds |= gfx::Rect(rc.x, 0, rc.w, height);
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

        m_bounds |= gfx::Rect(rc.x, 0, rc.w, height);
                              ^


for (int i=0; i<info.glyphCount; ++i) {
auto rc = info.getGlyphBounds(i);
m_bounds |= gfx::Rect(rc.x, 0, rc.w, height);
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

        m_bounds |= gfx::Rect(rc.x, 0, rc.w, height);
                                       ^


for (int i=0; i<info.glyphCount; ++i) {
auto rc = info.getGlyphBounds(i);
m_bounds |= gfx::Rect(rc.x, 0, rc.w, height);
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'float' to 'int' [bugprone-narrowing-conversions]

        m_bounds |= gfx::Rect(rc.x, 0, rc.w, height);
                                             ^

This new font selector list installed fonts with its proper name. It
needs some extra work yet to select font set styles (regular, bold,
italic, etc.)
If we clicked bold/italic, and then choose another font family, we were
using the cached typeface inside the FontInfo instead of an update
typeface with the selected styles applied (bold/italic).

Now we don't cache the typeface inside FontInfo to avoid this.
…t run

This fixes the required output image size to render text in different
languages when the text does't support the full range of the specified
chars/code points.
This is the first (not yet production-ready) version of the
interactive Text tool. The text input is done with a transparent
ui::Entry, and on each text modification an ExtraCel is rendered with
this same ui::Entry's TextBlob to be displated in the canvas with the
active zoom level.

The ui::Entry is being painted along the text in the canvas (just for
testing), but this is something to be fixed. Probably it will not be
the case in the future and a fully customized rendering (onPaint())
process will be required.
Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

// static
FontInfo FontInfo::getFromPreferences()
{
Preferences& pref = Preferences::instance();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'pref' of type 'Preferences &' can be declared 'const' [misc-const-correctness]

Suggested change
Preferences& pref = Preferences::instance();
Preferences const& pref = Preferences::instance();


void FontInfo::updatePreferences()
{
Preferences& pref = Preferences::instance();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'pref' of type 'Preferences &' can be declared 'const' [misc-const-correctness]

Suggested change
Preferences& pref = Preferences::instance();
Preferences const& pref = Preferences::instance();

public:
FontSelector(ContextBar* contextBar) {
// Load the font from the preferences
Preferences& pref = Preferences::instance();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'pref' of type 'Preferences &' can be declared 'const' [misc-const-correctness]

Suggested change
Preferences& pref = Preferences::instance();
s const

}

~FontSelector() {
Preferences& pref = Preferences::instance();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'pref' of type 'Preferences &' can be declared 'const' [misc-const-correctness]

Suggested change
Preferences& pref = Preferences::instance();
{ const

@@ -2200,6 +2220,11 @@
(tool->getInk(0)->isSlice() ||
tool->getInk(1)->isSlice());

// True if the current tool is text tool.
const bool isText = tool &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: implicit conversion 'tools::Tool *' -> bool [readability-implicit-bool-conversion]

Suggested change
const bool isText = tool &&
.( != nullptr)


void WritingTextState::onEnterState(Editor* editor)
{
StateWithWheelBehavior::onEnterState(editor);
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: qualified name 'StateWithWheelBehavior::onEnterState' refers to a member overridden in subclass; did you mean 'app::StandbyState'? [bugprone-parent-virtual-call]

Suggested change
StateWithWheelBehavior::onEnterState(editor);
app::StandbyState::onEnterState(editor);

Comment on lines +299 to +302
else {
editor->releaseMouse();
return KeepState;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: do not use 'else' after 'return' [readability-else-after-return]

Suggested change
else {
editor->releaseMouse();
return KeepState;
}
editor->releaseMouse();
return KeepState;


void WritingTextState::onFontChange()
{
FontInfo fontInfo = App::instance()->contextBar()->fontInfo();
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'fontInfo' of type 'FontInfo' can be declared 'const' [misc-const-correctness]

Suggested change
FontInfo fontInfo = App::instance()->contextBar()->fontInfo();
FontInfo const fontInfo = App::instance()->contextBar()->fontInfo();

const FontInfo& fontInfo,
const std::string& text)
{
text::FontRef font = get_font_from_info(fontInfo);
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'font' of type 'text::FontRef' (aka 'Ref') can be declared 'const' [misc-const-correctness]

Suggested change
text::FontRef font = get_font_from_info(fontInfo);
text::FontRef const font = get_font_from_info(fontInfo);

const std::string& text,
gfx::Color color)
{
text::FontRef font = get_font_from_info(fontInfo);
Copy link
Collaborator

Choose a reason for hiding this comment

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

warning: variable 'font' of type 'text::FontRef' (aka 'Ref') can be declared 'const' [misc-const-correctness]

Suggested change
text::FontRef font = get_font_from_info(fontInfo);
text::FontRef const font = get_font_from_info(fontInfo);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New font selector Textbox tool
2 participants