fix(editor): adapt font size in turbo renderer (#10858)
This commit is contained in:
@@ -39,6 +39,10 @@ export class ParagraphLayoutHandlerExtension extends BlockLayoutHandlerExtension
|
|||||||
};
|
};
|
||||||
|
|
||||||
paragraphNodes.forEach(paragraphNode => {
|
paragraphNodes.forEach(paragraphNode => {
|
||||||
|
const computedStyle = window.getComputedStyle(paragraphNode);
|
||||||
|
const fontSizeStr = computedStyle.fontSize;
|
||||||
|
const fontSize = parseInt(fontSizeStr);
|
||||||
|
|
||||||
const sentences = segmentSentences(paragraphNode.textContent || '');
|
const sentences = segmentSentences(paragraphNode.textContent || '');
|
||||||
const sentenceLayouts = sentences.map(sentence => {
|
const sentenceLayouts = sentences.map(sentence => {
|
||||||
const sentenceRects = getSentenceRects(paragraphNode, sentence);
|
const sentenceRects = getSentenceRects(paragraphNode, sentence);
|
||||||
@@ -60,6 +64,7 @@ export class ParagraphLayoutHandlerExtension extends BlockLayoutHandlerExtension
|
|||||||
return {
|
return {
|
||||||
text: sentence,
|
text: sentence,
|
||||||
rects,
|
rects,
|
||||||
|
fontSize,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { BlockLayoutPainterExtension } from '@blocksuite/affine-gfx-turbo-render
|
|||||||
interface SentenceLayout {
|
interface SentenceLayout {
|
||||||
text: string;
|
text: string;
|
||||||
rects: TextRect[];
|
rects: TextRect[];
|
||||||
|
fontSize: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ParagraphLayout extends BlockLayout {
|
export interface ParagraphLayout extends BlockLayout {
|
||||||
@@ -24,8 +25,7 @@ const meta = {
|
|||||||
|
|
||||||
const debugSentenceBorder = false;
|
const debugSentenceBorder = false;
|
||||||
|
|
||||||
function getBaseline() {
|
function getBaseline(fontSize: number) {
|
||||||
const fontSize = 15;
|
|
||||||
const lineHeight = 1.2 * fontSize;
|
const lineHeight = 1.2 * fontSize;
|
||||||
|
|
||||||
const A = fontSize * (meta.hHeadAscent / meta.emSize); // ascent
|
const A = fontSize * (meta.hHeadAscent / meta.emSize); // ascent
|
||||||
@@ -89,12 +89,14 @@ class ParagraphLayoutPainter implements BlockLayoutPainter {
|
|||||||
|
|
||||||
if (!isParagraphLayout(layout)) return; // cast to ParagraphLayout
|
if (!isParagraphLayout(layout)) return; // cast to ParagraphLayout
|
||||||
|
|
||||||
const fontSize = 15;
|
|
||||||
ctx.font = `300 ${fontSize}px Inter`;
|
|
||||||
const baselineY = getBaseline();
|
|
||||||
const renderedPositions = new Set<string>();
|
const renderedPositions = new Set<string>();
|
||||||
|
|
||||||
layout.sentences.forEach(sentence => {
|
layout.sentences.forEach(sentence => {
|
||||||
|
const fontSize = sentence.fontSize;
|
||||||
|
const baselineY = getBaseline(fontSize);
|
||||||
|
if (fontSize !== 15) return; // TODO: fine-tune for heading font sizes
|
||||||
|
|
||||||
|
ctx.font = `${fontSize}px Inter`;
|
||||||
ctx.strokeStyle = 'yellow';
|
ctx.strokeStyle = 'yellow';
|
||||||
sentence.rects.forEach(textRect => {
|
sentence.rects.forEach(textRect => {
|
||||||
const x = textRect.rect.x - layoutBaseX;
|
const x = textRect.rect.x - layoutBaseX;
|
||||||
|
|||||||
Reference in New Issue
Block a user