From 07e338d71717806d248569215905052bd3cee550 Mon Sep 17 00:00:00 2001 From: Bill Kendrick Date: Wed, 25 Dec 2024 13:42:25 -0800 Subject: [PATCH] Text/Label paste: Word-wrap on space (eaten) or dash --- docs/CHANGES.txt | 8 ++++---- docs/en/README.txt | 5 +++-- docs/en/html/README.html | 2 +- docs/es_ES.UTF-8/README.txt | 5 +++-- docs/es_ES.UTF-8/html/README.html | 2 +- docs/fr_FR.UTF-8/README.txt | 5 +++-- docs/fr_FR.UTF-8/html/README.html | 2 +- docs/gl_ES.UTF-8/README.txt | 5 +++-- docs/gl_ES.UTF-8/html/README.html | 2 +- docs/is_IS.UTF-8/README.txt | 5 +++-- docs/is_IS.UTF-8/html/README.html | 2 +- docs/ja_JP.UTF-8/README.txt | 5 +++-- docs/ja_JP.UTF-8/html/README.html | 2 +- docs/sq_AL.UTF-8/README.txt | 5 +++-- docs/sq_AL.UTF-8/html/README.html | 2 +- src/tuxpaint.c | 24 +++++++++++++++++++++--- 16 files changed, 53 insertions(+), 28 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index d3cee73d3..ce4a43fd7 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -9,11 +9,11 @@ https://tuxpaint.org/ 2024.December.25 (0.9.35) * Text & Label Tool Improvements: ------------------------------- - + WIP It is now possible to paste text from the copy/paste clipboard + + It is now possible to paste text from the copy/paste clipboard into Tux Paint. If text goes beyond the right of the canvas, - a new line is created. If text goes beyond the bottom of the - canvas, the text is truncated there. - - TODO: Improve word-wrapping (word-based, not character) + the text is word-wrapped at the previous space (' ') or dash ('-'), + if any, and a new line is created. If text goes beyond the bottom + of the canvas, the text is truncated there. Closes https://sourceforge.net/p/tuxpaint/feature-requests/95/ Bill Kendrick diff --git a/docs/en/README.txt b/docs/en/README.txt index 1068a128a..8abd3b687 100644 --- a/docs/en/README.txt +++ b/docs/en/README.txt @@ -495,8 +495,9 @@ e."Text" and "Label" Tools ← Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen - keyboard. The text will wrap to the next line if it hits the right edge of - the canvas. If the text hits the bottom of the canvas, the pasting will + keyboard. If the text would exceed the right edge of the canvas, it will + wrap to a new line of text (going back to the previous space or dash ('-') + if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text. Clicking elsewhere in the picture while the text entry is still active diff --git a/docs/en/html/README.html b/docs/en/html/README.html index 3b13e6b08..2bb18727a 100644 --- a/docs/en/html/README.html +++ b/docs/en/html/README.html @@ -823,7 +823,7 @@ Alternatively, press [Tab] and the text will be drawn onto the picture, but the cursor will move to the right of the text, rather than down a line, and to the left. (This can be useful to create a line of text with mixed colors, fonts, styles and sizes.)

- Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. The text will wrap to the next line if it hits the right edge of the canvas. If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

+ Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. If the text would exceed the right edge of the canvas, it will wrap to a new line of text (going back to the previous space or dash ('-') if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

Clicking elsewhere in the picture while the text entry is still active causes the current line of text to move to that location (where you can continue editing it).

diff --git a/docs/es_ES.UTF-8/README.txt b/docs/es_ES.UTF-8/README.txt index 68d07661d..430ae7711 100644 --- a/docs/es_ES.UTF-8/README.txt +++ b/docs/es_ES.UTF-8/README.txt @@ -495,8 +495,9 @@ e."Text" and "Label" Tools ← Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen - keyboard. The text will wrap to the next line if it hits the right edge of - the canvas. If the text hits the bottom of the canvas, the pasting will + keyboard. If the text would exceed the right edge of the canvas, it will + wrap to a new line of text (going back to the previous space or dash ('-') + if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text. Clicking elsewhere in the picture while the text entry is still active diff --git a/docs/es_ES.UTF-8/html/README.html b/docs/es_ES.UTF-8/html/README.html index ca130cdda..afedb7291 100644 --- a/docs/es_ES.UTF-8/html/README.html +++ b/docs/es_ES.UTF-8/html/README.html @@ -823,7 +823,7 @@ Alternatively, press [Tab] and the text will be drawn onto the picture, but the cursor will move to the right of the text, rather than down a line, and to the left. (This can be useful to create a line of text with mixed colors, fonts, styles and sizes.)

- Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. The text will wrap to the next line if it hits the right edge of the canvas. If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

+ Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. If the text would exceed the right edge of the canvas, it will wrap to a new line of text (going back to the previous space or dash ('-') if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

Clicking elsewhere in the picture while the text entry is still active causes the current line of text to move to that location (where you can continue editing it).

diff --git a/docs/fr_FR.UTF-8/README.txt b/docs/fr_FR.UTF-8/README.txt index 74c165c9a..847289b6c 100644 --- a/docs/fr_FR.UTF-8/README.txt +++ b/docs/fr_FR.UTF-8/README.txt @@ -525,8 +525,9 @@ e.Outils "Texte" et "Étiquette" ← Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen - keyboard. The text will wrap to the next line if it hits the right edge of - the canvas. If the text hits the bottom of the canvas, the pasting will + keyboard. If the text would exceed the right edge of the canvas, it will + wrap to a new line of text (going back to the previous space or dash ('-') + if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text. Cliquer ailleurs dans l'image alors que l'entrée de texte est toujours diff --git a/docs/fr_FR.UTF-8/html/README.html b/docs/fr_FR.UTF-8/html/README.html index 3a0d56a4f..9ecc60c54 100644 --- a/docs/fr_FR.UTF-8/html/README.html +++ b/docs/fr_FR.UTF-8/html/README.html @@ -823,7 +823,7 @@ Sinon, appuyez sur [Tab] et le texte sera inclus dans l'image, mais le curseur se déplacera vers la droite du texte, plutôt que vers le bas d'une ligne et vers la gauche. (Cela peut être utile pour créer une ligne de texte avec des couleurs, des polices, des styles et des tailles variés.)

- Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. The text will wrap to the next line if it hits the right edge of the canvas. If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

+ Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. If the text would exceed the right edge of the canvas, it will wrap to a new line of text (going back to the previous space or dash ('-') if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

Cliquer ailleurs dans l'image alors que l'entrée de texte est toujours active entraîne le déplacement de la ligne de texte actuelle vers cet emplacement (et vous pouvez continuer à la modifier).

diff --git a/docs/gl_ES.UTF-8/README.txt b/docs/gl_ES.UTF-8/README.txt index 89ca5e6ab..177130c75 100644 --- a/docs/gl_ES.UTF-8/README.txt +++ b/docs/gl_ES.UTF-8/README.txt @@ -503,8 +503,9 @@ e.Ferramentas «Texto» e «Etiquetas» ← Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen - keyboard. The text will wrap to the next line if it hits the right edge of - the canvas. If the text hits the bottom of the canvas, the pasting will + keyboard. If the text would exceed the right edge of the canvas, it will + wrap to a new line of text (going back to the previous space or dash ('-') + if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text. Ao premer noutro lugar da imaxe mentres a entrada de texto aínda está diff --git a/docs/gl_ES.UTF-8/html/README.html b/docs/gl_ES.UTF-8/html/README.html index 507d94620..47b4dd3d7 100644 --- a/docs/gl_ES.UTF-8/html/README.html +++ b/docs/gl_ES.UTF-8/html/README.html @@ -823,7 +823,7 @@ Como alternativa, prema [Tab] e o texto será debuxado na imaxe, mais o cursor moverase á dereita do texto, no canto de baixar unha liña e á esquerda. (Isto pode ser útil para crear unha liña de texto con cores, tipos de letra, estilos e tamaños mesturados.)

- Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. The text will wrap to the next line if it hits the right edge of the canvas. If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

+ Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. If the text would exceed the right edge of the canvas, it will wrap to a new line of text (going back to the previous space or dash ('-') if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

Ao premer noutro lugar da imaxe mentres a entrada de texto aínda está activa, a liña de texto actual moverase a esa posición (onde pode continuar editándoa).

diff --git a/docs/is_IS.UTF-8/README.txt b/docs/is_IS.UTF-8/README.txt index ef17d8207..3911301b4 100644 --- a/docs/is_IS.UTF-8/README.txt +++ b/docs/is_IS.UTF-8/README.txt @@ -495,8 +495,9 @@ e."Text" and "Label" Tools ← Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen - keyboard. The text will wrap to the next line if it hits the right edge of - the canvas. If the text hits the bottom of the canvas, the pasting will + keyboard. If the text would exceed the right edge of the canvas, it will + wrap to a new line of text (going back to the previous space or dash ('-') + if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text. Clicking elsewhere in the picture while the text entry is still active diff --git a/docs/is_IS.UTF-8/html/README.html b/docs/is_IS.UTF-8/html/README.html index b7c1f369c..3cea9e375 100644 --- a/docs/is_IS.UTF-8/html/README.html +++ b/docs/is_IS.UTF-8/html/README.html @@ -823,7 +823,7 @@ Alternatively, press [Tab] and the text will be drawn onto the picture, but the cursor will move to the right of the text, rather than down a line, and to the left. (This can be useful to create a line of text with mixed colors, fonts, styles and sizes.)

- Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. The text will wrap to the next line if it hits the right edge of the canvas. If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

+ Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. If the text would exceed the right edge of the canvas, it will wrap to a new line of text (going back to the previous space or dash ('-') if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

Clicking elsewhere in the picture while the text entry is still active causes the current line of text to move to that location (where you can continue editing it).

diff --git a/docs/ja_JP.UTF-8/README.txt b/docs/ja_JP.UTF-8/README.txt index 22c0289e0..5c4b247af 100644 --- a/docs/ja_JP.UTF-8/README.txt +++ b/docs/ja_JP.UTF-8/README.txt @@ -450,8 +450,9 @@ e.「もじ」ツール、「ラベル」ツール ← Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen - keyboard. The text will wrap to the next line if it hits the right edge of - the canvas. If the text hits the bottom of the canvas, the pasting will + keyboard. If the text would exceed the right edge of the canvas, it will + wrap to a new line of text (going back to the previous space or dash ('-') + if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text. 文字の入力中に別の場所をクリックすると、入力内容を維持したまま、文字を貼り diff --git a/docs/ja_JP.UTF-8/html/README.html b/docs/ja_JP.UTF-8/html/README.html index d837b1eb1..63cc2bcda 100644 --- a/docs/ja_JP.UTF-8/html/README.html +++ b/docs/ja_JP.UTF-8/html/README.html @@ -823,7 +823,7 @@ また、[Tab]キーを押すと、文字が描画された後、カーソルは、次の行ではなく、右側に移動します。これは、1行の中で異なったフォント、字体、フォントサイズ、色などを混在させたい場合に便利な方法です。

- Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. The text will wrap to the next line if it hits the right edge of the canvas. If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

+ Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. If the text would exceed the right edge of the canvas, it will wrap to a new line of text (going back to the previous space or dash ('-') if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

文字の入力中に別の場所をクリックすると、入力内容を維持したまま、文字を貼り付ける位置をクリックした位置に移動させ、文字入力を続けることができます。

diff --git a/docs/sq_AL.UTF-8/README.txt b/docs/sq_AL.UTF-8/README.txt index 8ccf6fc1b..a9a6a9b13 100644 --- a/docs/sq_AL.UTF-8/README.txt +++ b/docs/sq_AL.UTF-8/README.txt @@ -496,8 +496,9 @@ e.Mjete “Tekst” dhe “Etiketa” ← Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen - keyboard. The text will wrap to the next line if it hits the right edge of - the canvas. If the text hits the bottom of the canvas, the pasting will + keyboard. If the text would exceed the right edge of the canvas, it will + wrap to a new line of text (going back to the previous space or dash ('-') + if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text. Clicking elsewhere in the picture while the text entry is still active diff --git a/docs/sq_AL.UTF-8/html/README.html b/docs/sq_AL.UTF-8/html/README.html index 2d92b459c..73d2f5e0a 100644 --- a/docs/sq_AL.UTF-8/html/README.html +++ b/docs/sq_AL.UTF-8/html/README.html @@ -823,7 +823,7 @@ Alternatively, press [Tasti Tab] and the text will be drawn onto the picture, but the cursor will move to the right of the text, rather than down a line, and to the left. (This can be useful to create a line of text with mixed colors, fonts, styles and sizes.)

- Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. The text will wrap to the next line if it hits the right edge of the canvas. If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

+ Text from the clipboard (copy/paste buffer) can be inserted with the "Text" and "Label" tools by pressing the [Control] + [V] key combination on a physical keyboard, or clicking the "Paste" button in Tux Paint's on-screen keyboard. If the text would exceed the right edge of the canvas, it will wrap to a new line of text (going back to the previous space or dash ('-') if possible). If the text hits the bottom of the canvas, the pasting will abort, truncating the text.

Clicking elsewhere in the picture while the text entry is still active causes the current line of text to move to that location (where you can continue editing it).

diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 0f5e7bf00..59d4de3d7 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - December 20, 2024 + June 14, 2002 - December 25, 2024 */ #include "platform.h" @@ -3198,10 +3198,28 @@ static void mainloop(void) txt_width = do_render_cur_text(0); if (cursor_x + txt_width > canvas->w && texttool_len > 1) { - texttool_str[texttool_len - 1] = '\0'; + int best, j, rewind; + + best = -1; + + for (j = texttool_len - 1; j >= 0 && best == -1; j--) { + if (texttool_str[j] == ' ') { + best = j + 1; /* +1 to eat the space */ + } else if (texttool_str[j] == '-') { /* FIXME: Also en-dash, em-dash, others? -bjk 2024.12.25 */ + best = j; + } + } + + if (best == -1) { + best = texttool_len - 1; + } + + rewind = texttool_len - best; + + texttool_str[best] = '\0'; txt_width = do_render_cur_text(0); exceeded = text_label_tool_enter(TuxPaint_Font_FontHeight(getfonthandle(cur_font))); - i--; + i = i - rewind; } SDL_Delay(10); }