We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Adding stroke/borders to text
Page Index Toggle Pages: 1
Adding stroke/borders to text (Read 5082 times)
Adding stroke/borders to text
Aug 12th, 2009, 10:21pm
 
Is it possible to add a stroke/border to text? I've tried NextText but it is quite slow for something simple like a border. I won't be using the other NextText features, so using that is kinda overkill.
Re: Adding stroke/borders to text
Reply #1 - Aug 13th, 2009, 6:51am
 
There's really no simple way to do this, because Text is displayed as a rectangular bitmap, not individual letters. So the only way you're going to be able to do it, is to use some text library. Did you try NextText with the OpenGL renderer? It should fix your performance problems.
Re: Adding stroke/borders to text
Reply #2 - Aug 13th, 2009, 7:31am
 
maybe its possible using the geomerative library too
http://www.ricardmarxer.com/processing/geomerative/documentation/

Re: Adding stroke/borders to text
Reply #3 - Aug 13th, 2009, 3:51pm
 
Using NextText with OpenGL seems to make things slower and more choppy.

The Geomerative library seems to be the answer I'm looking for but it doesn't work with the current version of processing. Is there any way to force it to work, short of going through the source and fixing everything?

What I'm trying to do is make a timer/counter. The background is constantly changing, so if it doesn't have a border around the text, it will not be visible.

Example using OpenGL and NextText(not tested, real one is a lot longer):

Code:

int num = 1234

Book book = new Book();
setup(){
  size(100,100,OPENGL);
  fill(255);
  stroke(0);
  strokeWeight(5);
}
draw(){
  book.clear();
  num++;
  book.addText(str(num));
  book.stepAndDraw();
}


Am I doing something wrong here that is causing it to run slow?

EDIT: geomerative link posted is outdated, the one on the library page is up to date.
Re: Adding stroke/borders to text
Reply #4 - Aug 13th, 2009, 7:32pm
 
Im new to this but could you use adobe illustrator to create the text and add outlines there and then import the vector objects using PShape

http://processing.org/learning/basics/loaddisplayshape.html
Re: Adding stroke/borders to text
Reply #5 - Aug 14th, 2009, 4:20pm
 
That might work, but I would have to export each character to .svg one at a time. Also, I saw somewhere that importing .svg files is quite slow in processing. I think that's what it says on the vertext processing library site.

Geomerative is able to do what I want, and it's fast. So I'll stick to that for now.
Re: Adding stroke/borders to text
Reply #6 - Aug 15th, 2009, 9:08am
 
Your above code is not even close to working, so maybe just post your entire project in a zip somewhere so we could download and take a look.
Re: Adding stroke/borders to text
Reply #7 - Aug 15th, 2009, 3:40pm
 
I'm not sure where/how to post a .zip. Below is a copy of the code that works and a screenshot.

NextText gives this weird broken stroke on the text.

Also, is it correct to use book.clear() every time I want to add new text?

This is the working code:

Code:
import net.nexttext.behaviour.dform.*;
import net.nexttext.behaviour.*;
import net.nexttext.behaviour.control.*;
import net.nexttext.behaviour.physics.*;
import net.nexttext.renderer.*;
import net.nexttext.*;
import net.nexttext.property.*;
import net.nexttext.behaviour.standard.*;
import net.nexttext.input.*;

int num = 1234;

Book book;
PFont font;
PImage bg;

void setup(){
 size(400,400);
 book = new Book(this);
 font = createFont("GeometricBlack.ttf",48); //replace with something else
 bg = createImage(400,400,RGB);
 textFont(font);
 textAlign(CENTER);
 fill(255);
 stroke(0);
 strokeWeight(5);
}

void draw(){
 bg.loadPixels();
 PImage dashed = get(0,mouseY,400,1);
 for(int i = 0; i<dashed.pixels.length; i++){ //colorful line
     dashed.pixels[i] = color(int(random(255)),int(random(255)),int(random(255)));
 }
 background(255);
 book.clear();
 num++;
 book.addText(str(num),mouseX,mouseY);
 book.stepAndDraw();
 image(dashed,0,mouseY); //colorful line follows mouse
}


Screenshot:
...
Re: Adding stroke/borders to text
Reply #8 - Aug 16th, 2009, 3:05am
 
Maybe i would do it like this : Code:
PFont font;

void setup(){
size(400,400);

// println(PFont.list());

font = createFont("Arial",48); //replace with something else

textFont(font);
textAlign(CENTER);
fill(255);
stroke(0);
strokeWeight(5);
}
void draw(){

fill(0);
text("1234",104,104);
fill(255);
text("1234",100,100);
}


its not a outline but creates a shadow like effekt that helps to increase readability too... another way would be to find a font which exists in 2 different types, outline non outline version and is monospaced, then you can get your outline by just overlaying 2 fonts.
Re: Adding stroke/borders to text
Reply #9 - Aug 16th, 2009, 6:26pm
 
I've tried doing a shadow like effect, it is somewhat visible when the background is the same colour as the text, but it doesn't look very nice. The text also appears to jump when the background becomes the text colour.

I have found a font that has an outline and non-outline version. but they are not monospaced so I will have to manually line them up letter-by-letter, doing that might slow things down.

But first, any idea why NextText gives a messed up stroke like the above picture? Geomerative also has the same problem. It gets more messed up when the font size is small, ~16.
Re: Adding stroke/borders to text
Reply #10 - Aug 17th, 2009, 12:47am
 
seems to be a problem with the library, happens with one of them their examples using outlines, too... http://www.nexttext.net/applet/puller/
Re: Adding stroke/borders to text
Reply #11 - Aug 17th, 2009, 2:07pm
 
I thought that was an intended effect. Guess I should switch back to geomerative or something.
Page Index Toggle Pages: 1