Missing characters of font exported PDF

hi, i want to make some ascii art exported as pdf for larger print.
…tried with several fonts using processing.pdf
some arn’t working at all some do partly, especially the extra characters i’d like to work with are always missing (dots, triangles, crosses, stars,…)

what i found in the forum so far is, that the processing.pdf library is just not build for that and doesn’t support these characters…

is that right? is there another way? …thank you!

here the script:

import processing.pdf.*; 
PFont fontA, datefont;
PImage img;
int resolution = 10;
char[] ascii;
int number;

void setup() {
  size(600,1000);
  background(255);

  number=(int)random(999);
  beginRecord(PDF, number +"_ascii1.pdf");
  img = loadImage("01.jpg");  

  grid();

  ascii = new char[256];

  String letters = "♂░►_-♠*\◙▀▲∕●MN@#$o;:,. ";

  for (int i = 0; i < 256; i++) {
    int index = int(map(i, 0, 256, 0, letters.length()));
    ascii[i] = letters.charAt(index);
  }

  PFont mono = createFont("Arial", resolution + 2); // some fonts work partly... Arial Verdana 
  textFont(mono);
  textSize(resolution);

  ascii();
}


void draw() {
  frameRate(1);

  endRecord();
  saveFrame(number+"_ascii_03_5_2.png");

  //setup();
  //exit();
  noLoop(); 
}

void ascii() {
  img.loadPixels();
  img.filter(INVERT);
  for (int y = 0; y < img.height; y += resolution) {
    for (int x = 0; x < img.width; x += resolution) {
      color pixel = img.pixels[y * img.width + x];
      fill(pixel);
      text(ascii[int(brightness(pixel))], x, y);
    }
  }
}

void grid() {
  img.loadPixels();
  for(int h=0; h<height; h+=resolution){
    for(int w=0; w<width; w+=resolution){

      color pixel = img.pixels[h * img.width + w];

      fill(pixel);
      stroke(0,111);
      strokeWeight(0.5);
      rect(w,h,resolution,resolution);
    }
  }
}
1 Like

Some things you might consider:

Judging based on your comment that some of the fonts work partly I’m guessing whatever font you use doesn’t support the uncommon characters that you have in your sketch. So trying finding a font that supports all the characters. I think I’ve heard them called complete fonts somewhere but I don’t know if that’s the correct term.

Another thing you could try is forcing the pdf exporter to draw the characters as fonts with shapes with the line textMode(SHAPE) right after size in setup.

If neither of those work I would just save the text to a txt file and then paste it into indesign (or word if you don’t have indesign) to create a large print.

2 Likes

thank you!
textMode(SHAPE) didn’t do anything, neither did the search for ‘complete fonts’:frowning:
to do it with external vector app ist not really tempting, since i later want to work with random layering and sorts…
i’d like a relatively exact controllable graphic, so next i want to try to work with a set of svg files instead of font. didn’t do this before, …would be great to get some help how to use an svg file array and use it dependent on its portion of black to convert the image into an svg collage following brightness…

should i better put this question it in a new post?

sorry because the formatting; still working with p5 1.1 since many older scripts…

Using .svg will probably be a bit more work. I would start by loading the .svg files in as PShapes. Because svg are vector based and not pixel based you can’t easily calcuate their relative brightness without first converting them to pixels. You could render each one to a PGraphics instance and use the pixels array (PGraphics extends PImage so it has a pixels array just like PImage) to find out the average brightness of all the pixels. It would probably be best to encapsulate this in a class. Then you could use a similar process to what you’re doing in your example. Where you look for the PShape with the closest average brightness to the brightness of the individual pixel.

Note: Not sure what you mean by p5 1.1. p5 uses an entirely different language to Processing, It uses JavaScript while Processing uses Java (not related to JavaScript in any way besides name). Your code looks like it’s Processing/Java syntax. If you’re still using Processing 1.1 I highly recommend upgrading to 3.4 at least for new projects. 3.4 should be mostly backwards compatible and be far less buggy. Unless you’re using a library that hasn’t been upgraded to Processing 3 then the latest stable version is the way to go.

1 Like

hi figraham, thanx for your answer, that makes sense indeed, I’ll try to do that…

1 Like