Skip to content

Seeking feedback: Charming Pretext extension for flowing text inside shapes #99

@pearmini

Description

@pearmini

Hi @chenglou!

Thank you so much for creating this brilliant library! It’s really exciting to see how text can flow with such expressive control and a concise, elegant API design. I’m a toolmaker interested in data visualization and generative art. To make it easier to create text-based visualizations and generative pieces, I built an extension on top of Pretext called Charming Pretext. Here’s a quick example:

Image
import * as cm from "charmingjs";

const layout = cm.layoutTextInPath({
  text: "Hello, Charming Pretext! I love generative art!", // Filling the path with this text
  path: cm.pathCircle(160, 160, 150), // Built a circle path.
  fontSize: 12,
  fontFamily: "Inter",
});

context.font = `${layout.fontSize}px ${layout.fontFamily}`;
context.textAlign = "center";
context.textBaseline = "middle";

for (const t of layout.texts) {
  context.save();
  context.translate(t.x, t.y);
  context.rotate((t.angle * Math.PI) / 180);
  context.fillText(t.text, 0, 0);
  context.restore();
}

It essentially allows text to flow within arbitrary shapes defined by SVG paths. I’ve also created a few demos to explore its potential.

Image Image Image

I’m not entirely sure if this is the best approach to implementing something like this, so I would really appreciate any feedback or suggestions you might have.

Thanks again for your inspiring work on this project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions