Skip to content

Visualize Your Ideas With Code

fix(2d): fix #179 by replacing fontBoundingBoxDescent (#249)

DJ20a4d65bbfa0
diff --git a/packages/2d/src/components/Text.ts b/packages/2d/src/components/Text.ts
index 5e750cb3..6bf92d90 100644
--- a/packages/2d/src/components/Text.ts
+++ b/packages/2d/src/components/Text.ts
@@ -77,10 +77,9 @@ export class Text extends Shape {
text: string,
rect: Rect,
) {
- const y =
- rect.y +
- rect.height / 2 +
- context.measureText(text).fontBoundingBoxDescent;
+ const y = rect.y + rect.height / 2;
+ const oldBaseline = context.textBaseline;
+ context.textBaseline = 'middle';
if (this.lineWidth() <= 0) {
context.fillText(text, rect.x, y);
@@ -91,6 +90,8 @@ export class Text extends Shape {
context.fillText(text, rect.x, y);
context.strokeText(text, rect.x, y);
}
+
+ context.textBaseline = oldBaseline;
}
protected override updateLayout() {
diff --git a/packages/docs/docs/getting-started/hierarchy.mdx b/packages/docs/docs/getting-started/hierarchy.mdx
index ddc5445f..b819780e 100644
--- a/packages/docs/docs/getting-started/hierarchy.mdx
+++ b/packages/docs/docs/getting-started/hierarchy.mdx
@@ -6,7 +6,6 @@ slug: /hierarchy
import Mermaid from '@theme/Mermaid';
import CodeBlock from '@theme/CodeBlock';
import ApiSnippet from '@site/src/components/Api/ApiSnippet';
-import FirefoxTextWarning from '@site/src/warnings/FirefoxTextWarning';
# Scene hierarchy
@@ -17,8 +16,6 @@ the Document Object Model used to represent HTML and XML documents.
Here's an example of a simple scene hierarchy together with its object
representation:
-<FirefoxTextWarning />
-
<div className="row margin-bottom--md">
<div className="col col--6">
diff --git a/packages/docs/docs/getting-started/references.mdx b/packages/docs/docs/getting-started/references.mdx
index b883f517..edaf26c2 100644
--- a/packages/docs/docs/getting-started/references.mdx
+++ b/packages/docs/docs/getting-started/references.mdx
@@ -3,8 +3,6 @@ sidebar_position: 7
slug: /references
---
-import FirefoxTextWarning from '@site/src/warnings/FirefoxTextWarning';
-
# References
Usually, when creating a node, we want to store a reference to it, so we can
@@ -179,8 +177,6 @@ that we can use to animate all of them.
### Custom functions
-<FirefoxTextWarning />
-
`makeRef()` can also be used to return more than one reference from a custom
function component:
@@ -216,8 +212,6 @@ fill this object with all the necessary references.
## `makeRefs()` function
-<FirefoxTextWarning />
-
Looking at the previous example, you may notice that we had to define the `refs`
type twice. First in the `Label` declaration and then again when creating the
`label` object:
diff --git a/packages/docs/docs/getting-started/signals.mdx b/packages/docs/docs/getting-started/signals.mdx
index 35036acb..99ea1483 100644
--- a/packages/docs/docs/getting-started/signals.mdx
+++ b/packages/docs/docs/getting-started/signals.mdx
@@ -6,7 +6,6 @@ slug: /signals
import AnimationPlayer from '@site/src/components/AnimationPlayer';
import CodeBlock from '@theme/CodeBlock';
import signalSource from '!!raw-loader!@motion-canvas/examples/src/scenes/node-signal';
-import FirefoxTextWarning from '@site/src/warnings/FirefoxTextWarning';
# Signals
@@ -111,8 +110,6 @@ We can use the fact that properties of nodes are represented by signals to const
Below you'll find the code used to create this animation. We highlighted all the places where signals are used:
-<FirefoxTextWarning />
-
<CodeBlock language="tsx">{signalSource}</CodeBlock>
With this setup, all we need to do is animate the `radius` signal, and the rest of the scene will adjust accordingly:
diff --git a/packages/docs/src/warnings/FirefoxTextWarning.tsx b/packages/docs/src/warnings/FirefoxTextWarning.tsx
deleted file mode 100644
index 0fd20835..00000000
--- a/packages/docs/src/warnings/FirefoxTextWarning.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import React from 'react';
-import Admonition from '@site/src/theme/Admonition';
-import Link from '@docusaurus/Link';
-
-export default function FirefoxTextWarning() {
- return (
- <Admonition type="caution">
- If you are using Firefox make sure to check if{' '}
- <code>dom.textMetrics.fontBoundingBox</code> is enabled else you might not
- see the{' '}
- <Link to="/api/2d/components/Text">
- <code>Text</code>
- </Link>
- . You can enable this by navigating to <code>about:config</code>.
- </Admonition>
- );
-}