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

Horizontal Baseline Alignment for Multiple Text Objects #10216

Open
asturur opened this issue Oct 16, 2024 Discussed in #10213 · 0 comments
Open

Horizontal Baseline Alignment for Multiple Text Objects #10216

asturur opened this issue Oct 16, 2024 Discussed in #10213 · 0 comments
Labels

Comments

@asturur
Copy link
Member

asturur commented Oct 16, 2024

Discussed in #10213

Originally posted by eiLLFire October 15, 2024
I need the ability to select two or more text objects and align them horizontally based on their individual baselines. This feature would ensure that text objects with different font sizes, line heights, or font families can be aligned along a common baseline, ensuring a uniform appearance in the layout. How do I implement function getBaselinePosition
image

var text1 = new Text('Hello', {
  left: 100,
  top: 100,
  fontSize: 40,
});

var text2 = new Text('World', {
  fontFamliy: 'xxx',
  left: 200,
  top: 150,
  fontSize: 60,
});

canvas.add(text1, text2);

function getBaselinePosition(text) {
  // calculate its baseline based on its font metrics
}

var baseline1 = getBaselinePosition(text1);
var baseline2 = getBaselinePosition(text2);
if (baseline1 > baseline2) {
  text2.top += baseline1 - baseline2;
} else {
  text1.top += baseline2 - baseline1;
}
```</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant