VFont: Corrections to Cursor When on Curve #107307

Merged
Harley Acheson merged 2 commits from Harley/blender:CurveCursor into main 2023-04-27 22:07:08 +02:00
Member

Corrections to transformation and placement of the text cursor when the
text is being deformed by a curve.


When a text object is deformed by a curve the text cursor (caret) needs to be shown at an angle. Unfortunately this transformation isn't done correctly so the top and bottom edges are not aligned correctly and it become non-rectangular. And the angle quite often does not look quite right:

CursorCurve.png

The PR just transforms the cursor correctly so that it remains rectangular after rotation. And it chooses the rotation better, matching nicer on first and last character and to the beginning or end of a selection. Overall it just looks a bit better:

TextSelectCurve.gif

This PR is offered as a much simpler alternative to #107193.

Corrections to transformation and placement of the text cursor when the text is being deformed by a curve. ---- When a text object is deformed by a curve the text cursor (caret) needs to be shown at an angle. Unfortunately this transformation isn't done correctly so the top and bottom edges are not aligned correctly and it become non-rectangular. And the angle quite often does not look quite right: ![CursorCurve.png](/attachments/d626f428-7643-47c6-9646-c2cee8ae9e9e) The PR just transforms the cursor correctly so that it remains rectangular after rotation. And it chooses the rotation better, matching nicer on first and last character and to the beginning or end of a selection. Overall it just looks a bit better: ![TextSelectCurve.gif](/attachments/f780743d-e8f7-474c-8a5d-66141940edf9) This PR is offered as a much simpler alternative to #107193.
Harley Acheson added this to the User Interface project 2023-04-24 19:25:59 +02:00
Harley Acheson requested review from Campbell Barton 2023-04-25 17:46:08 +02:00
Campbell Barton requested changes 2023-04-26 03:12:47 +02:00
@ -1546,3 +1540,1 @@
f[0] = font_size * (-0.02f * co + ct->xof);
f[1] = font_size * (0.1f * si - (0.25f * co) + ct->yof);
float width = 0.02f;

These can be made const.

These can be made `const`.
Harley marked this conversation as resolved
@ -1549,0 +1542,4 @@
float left = ct->xof;
float bottom = ct->yof;
float rotation = ct->rot;
float caret_nudge = 0.0f;

Use term cursor instead of caret.

There should be an explanation why the nudge is needed, it also seems only to apply to the X axis, so cursor_offset_x with a description for why the small amount of X offset is needed (what does it solve?).

Use term `cursor` instead of `caret`. There should be an explanation why the nudge is needed, it also seems only to apply to the X axis, so `cursor_offset_x` with a description for why the small amount of X offset is needed (what does it solve?).
Harley marked this conversation as resolved
@ -1558,0 +1577,4 @@
float temp_fl[2];
rotate_v2_v2fl(temp_fl, &ef->textcurs[i][0], -rotation);
ef->textcurs[i][0] = font_size * (left + temp_fl[0]);
ef->textcurs[i][1] = font_size * (bottom + temp_fl[1] - 0.25f);

What does 0.25 represent? Applying an offset after rotation seems strange.

May as well assign to a const float with a descriptive name.

What does `0.25` represent? Applying an offset after rotation seems strange. May as well assign to a `const` float with a descriptive name.
Harley marked this conversation as resolved
Author
Member

@ideasman42 - I think I have made it easier to follow, including any need for that "nudge"

a description for why the small amount of X offset is needed (what does it solve?).

I put in detailed comments, but there are times when the cursor should align with the character to the right and sometimes to the left, like when there is a selection. if the cursor is at the left edge of a selection is is nice to move it to the edge of the selection rather than straddling it to show more of the selected text.

What does 0.25 represent? Applying an offset after rotation seems strange.

I am hoping my comments explain that enough. Basically when on a curve the characters are rotated by their bottom left corner. So the cursor's bottom-left corner is similarly in the correct position. If we apply offsets before rotation the cursor moves incorrectly because rotate_v2_v2fl rotates around {0,0), so here I am moving the cursor so that the rotation origin is where I want it, rotate, then apply offsets. I think it would be clearer if we had a version of rotate_v2_v2fl that could rotate around a different origin than just {0,0}.

Without that "0.25" downward movement the cursor would have its bottom point on the baseline, but we want it 75% above and 25% below so lines up better with most fonts that have descenders.

@ideasman42 - I think I have made it easier to follow, including any need for that "nudge" > a description for why the small amount of X offset is needed (what does it solve?). I put in detailed comments, but there are times when the cursor should align with the character to the right and sometimes to the left, like when there is a selection. if the cursor is at the left edge of a selection is is nice to move it to the edge of the selection rather than straddling it to show more of the selected text. > What does 0.25 represent? Applying an offset after rotation seems strange. I am hoping my comments explain that enough. Basically when on a curve the characters are rotated by their bottom left corner. So the cursor's bottom-left corner is similarly in the correct position. If we apply offsets before rotation the cursor moves incorrectly because `rotate_v2_v2fl` rotates around {0,0), so here I am moving the cursor so that the rotation origin is where I want it, rotate, then apply offsets. I think it would be clearer if we had a version of `rotate_v2_v2fl` that could rotate around a different origin than just {0,0}. Without that "0.25" downward movement the cursor would have its bottom point on the baseline, but we want it 75% above and 25% below so lines up better with most fonts that have descenders.
Campbell Barton approved these changes 2023-04-27 02:35:27 +02:00
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson force-pushed CurveCursor from 28ea3e0af1 to ac92a4a9bf 2023-04-27 20:25:19 +02:00 Compare
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson added 1 commit 2023-04-27 21:36:34 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
52d4738c9b
Calm Linux warning about shadowed vars
Author
Member

@blender-bot build

@blender-bot build
Harley Acheson merged commit 1d2eab9ab3 into main 2023-04-27 22:07:08 +02:00
Harley Acheson deleted branch CurveCursor 2023-04-27 22:07:09 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:44 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#107307
No description provided.