-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix text scale #1008 #1010
Fix text scale #1008 #1010
Conversation
(allowing to keep the text keep his proportions to the font)
Reviewer's Guide by SourceryThis PR implements text scaling functionality when transforming text elements, along with some code formatting improvements and dependency updates. The key changes ensure that font sizes are properly scaled when text elements are transformed, maintaining visual consistency. Class diagram for text scaling changesclassDiagram
class SvgCanvas {
+textActionsMethod()
}
class textActionsMethod {
+setCursor(index: Integer)
+setSelection(start: Integer, end: Integer, skipInput: boolean)
+getIndexFromPoint(mouseX: Float, mouseY: Float) Integer
+setCursorFromPoint(mouseX: Float, mouseY: Float)
+setEndSelectionFromPoint(x: Float, y: Float, apply: boolean)
+screenToPt(xIn: Float, yIn: Float) module:math.XYObject
+ptToScreen(xIn: Float, yIn: Float) module:math.XYObject
+selectAll(evt: Event)
+selectWord(evt: Event)
+select(target: Element, x: Float, y: Float)
+start(elem: Element)
+mouseDown(evt: external:MouseEvent, mouseTarget: Element, startX: Float, startY: Float)
+mouseMove(mouseX: Float, mouseY: Float)
+mouseUp(evt: external:MouseEvent, mouseX: Float, mouseY: Float)
+toEditMode(x: Float, y: Float)
+toSelectMode(selectElem: boolean|Element)
+setInputElem(elem: Element)
+clear()
+init(_inputElem: Element)
}
SvgCanvas --> textActionsMethod
class remapElement {
+remapElement(selected: Element, changes: Object, m: Object)
}
remapElement : +scale font-size
remapElement : +handle tspan font-size scaling
SvgCanvas --> remapElement
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jfhenon - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -177,6 +177,19 @@ export const remapElement = (selected, changes, m) => { | |||
const pt = remap(changes.x, changes.y) | |||
changes.x = pt.x | |||
changes.y = pt.y | |||
|
|||
// Scale font-size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider extracting the repeated font-size scaling logic into a reusable helper function
The font-size scaling logic is duplicated in three places. Consider extracting it to a helper function:
function getScaledFontSize(element, scaleFactorA) {
let fontSize = element.getAttribute('font-size') || window.getComputedStyle(element).fontSize;
const fontSizeNum = parseFloat(fontSize);
return !isNaN(fontSizeNum) ? fontSizeNum * Math.abs(scaleFactorA) : null;
}
Then simplify the text/tspan handling:
case 'text': {
const pt = remap(changes.x, changes.y);
changes.x = pt.x;
changes.y = pt.y;
const scaledFontSize = getScaledFontSize(selected, m.a);
if (scaledFontSize) changes['font-size'] = scaledFontSize;
finishUp();
// Handle child tspans
selected.querySelectorAll('tspan').forEach(child => {
const childChanges = {};
if (child.hasAttribute('x')) {
childChanges.x = remap(convertToNum('x', child.getAttribute('x')), changes.y).x;
}
if (child.hasAttribute('y')) {
childChanges.y = remap(changes.x, convertToNum('y', child.getAttribute('y'))).y;
}
const scaledChildFontSize = getScaledFontSize(child, m.a);
if (scaledChildFontSize) childChanges['font-size'] = scaledChildFontSize;
if (Object.keys(childChanges).length > 0) {
assignAttributes(child, childChanges, 1000, true);
}
});
break;
}
This reduces duplication while keeping the same functionality. The helper function makes the scaling logic more maintainable and the forEach loop flattens the tspan handling.
PR description
Checklist
Note that we require UI tests to ensure that the added feature will not be
nixed by some future fix and that there is at least some test-as-documentation
to indicate how the fix or enhancement is expected to behave.
npm test
, ensuring linting passes and that Cypress UI tests keepcoverage to at least the same percent (reflected in the coverage badge
that should be updated after the tests run)
help both for future users and for the PR reviewer.
Summary by Sourcery
Fix text scaling issue by adjusting font-size based on transformation matrix and improve code readability in text-actions.js. Update package dependencies to their latest versions.
Bug Fixes:
Enhancements:
Build: