vgonisanz
vgonisanz

Reputation: 11930

Concatenate dynamically-sized matrix in C++ using STD library

I have a text message like:

string text = "HELLO WORLD!"

And for each caracter a function that return a matrix with 0/1 if must put a "pixel" to draw the text:

matrix translate(char * value,int height);    
matrix translate("H",3);

Must return a matrix with this values:

101
111   equal <H>
101

Calling to translate function for each caracter, i want to store all the data in a dinamic matrix:

10101110...
11101100... equal <H><SPACE><E><SPACE>...  etc
10101110...

What is the best way to Store the values?

1) I have consider a matrix, but are statics.

2) I have consider using bi-dimensional vectors, but its very complicated to this problem.

3) I have consider use a big matrix when know final number of colums, but it depends of what letters are, I will need 1 iteration to count numer of colums (each letter could be larger than 3) and another one to store the data.

Upvotes: 2

Views: 181

Answers (1)

Thomas Matthews
Thomas Matthews

Reputation: 57718

Having worked with dot-matrix, ink jet and laser printers, I recommend that you have a fixed size matrix that has the maximum columns you would output.

For example, for a 8.5 inch wide paper at 600 dots per inch, there would be 5100 columns.

The rows depends on how many you will need or how many are convenient.

Also, you may want to use 5x7 matrix with a space == 5x7 blank (zeros). Leave some blank columns between letters and focus on a fixed-pitch or bitmap font.

For each character, you will want to have a matrix or a bitmap. Arrays work really well for this. A collection of bitmaps (matrices) associated with characters is called a font.

You may want to write matrix function for rotating the fonts from portrait orientation to landscape orientation and vice versa.

Edit 1:
You can't think in terms of columns per sentence, but how much of the sentence will fit into your buffer before you have to flush (or process) the buffer. Sentences can be very small to very large (look at this answer). Since the character matrices have fixed width and spacing between characters, determining if a character or many characters can fit is only a math function.

Upvotes: 2

Related Questions