No font in exported PDF
in
Core Library Questions
•
9 months ago
I have tried literally dozens of plotting, drawing, image processing, and page layout programs, including freeware and expensive commercial software, to do what I consider a moronically simple task. None of them do, in a simple manner, what I want to do. All I want to do is to create a circular layout with text on a circular path, some lines, and some images positioned at various points around the circle. Processing is by far the most feature-rich, simplest to script program I have found. While I'm sure I can create exactly what I want with it, the huge stumbling block is the PDF export library. I have tried for hours to get the exported PDF to contain the font that I specified in the script. No matter what font I try, I keep getting no fonts at all. The PDF displays text with some generic default font:
Here is the script:
-
// The message to be displayed
String message = "text along a curve";
PFont f;// The radius of a circlefloat r = 100;
import processing.pdf.*;
void setup() {size(400, 400);String[] fontList = PFont.list();println(fontList);f = createFont("Georgia",40,true);textFont(f);// The text must be centered!textAlign(CENTER);smooth();noLoop();beginRecord(PDF, "text_along_a_curve.pdf");}
void draw() {background(255);
// Start in the center and draw the circletranslate(width / 2, height / 2);noFill();stroke(0);ellipse(0, 0, r*2, r*2);
// We must keep track of our position along the curvefloat arclength = 0;
// For every boxfor (int i = 0; i < message.length(); i++){// Instead of a constant width, we check the width of each character.char currentChar = message.charAt(i);float w = textWidth(currentChar);
// Each box is centered so we move half the widtharclength += w/2;// Angle in radians is the arclength divided by the radius// Starting on the left side of the circle by adding PIfloat theta = PI + arclength / r;
pushMatrix();// Polar to cartesian coordinate conversiontranslate(r*cos(theta), r*sin(theta));// Rotate the boxrotate(theta+PI/2); // rotation is offset by 90 degrees// Display the characterfill(0);text(currentChar,0,0);popMatrix();// Move halfway againarclength += w/2;}endRecord();}
I have read and reread the
PDF Export page and found it not that helpful and outdated. I tried using
textMode(SHAPE) as advised there and it threw an exception. There is talk about adding a
.ttf file to the data directory. What data directory? "I don't see no data directory." So I am at wits' end about how to do this. I'm tired of "riddles in the dark." Being able to control the font in the output PDF is mandatory. Without this ability, the program is all but useless to me. So how do I go about doing this?
1