TTF to bitmap conversion needed!
Moderator: Rathinagiri
TTF to bitmap conversion needed!
Does sb. have (and can share) example, how to convert truetype fonts to bitmap?
Eg. given string, the name of font and size converted to bitmap (or array of bits....)
Best regards, Marek
Eg. given string, the name of font and size converted to bitmap (or array of bits....)
Best regards, Marek
Re: TTF to bitmap conversion needed!
Español:
Hola Marek,
En la HMG Extended Edition (http://hmgextended.com) hay en una carpeta:
\minigui\samples\applications\wbt\
una herramienta para crear botones para la WEB.
Si bien no es lo que realmente precisas, cambiando un poco el código
seguramente podras crear fuentes TTF en BMP's.
Espero que sea de utilidad
Saludos
Walter H.TAVERNA
Inglés:
Hello Marek,
In the HMG Extended Edition (http://hmgextended.com) is in a folder:
\ MiniGUI \ samples \ applications \ WBT \
a tool to create buttons for the Web.
While it is not really accurate, changing a little code
surely you can create TTF fonts in BMP's.
I hope it is useful
Regards
Walter H.TAVERN
Hola Marek,
En la HMG Extended Edition (http://hmgextended.com) hay en una carpeta:
\minigui\samples\applications\wbt\
una herramienta para crear botones para la WEB.
Si bien no es lo que realmente precisas, cambiando un poco el código
seguramente podras crear fuentes TTF en BMP's.
Espero que sea de utilidad
Saludos
Walter H.TAVERNA
Inglés:
Hello Marek,
In the HMG Extended Edition (http://hmgextended.com) is in a folder:
\ MiniGUI \ samples \ applications \ WBT \
a tool to create buttons for the Web.
While it is not really accurate, changing a little code
surely you can create TTF fonts in BMP's.
I hope it is useful
Regards
Walter H.TAVERN
Nada se pierde. Todo se transforma. (Lavoussier)
Nothing is lost. Everything changes.
Nothing is lost. Everything changes.
- Czarny_Pijar
- Posts: 172
- Joined: Thu Mar 18, 2010 11:31 pm
- Location: 19.2341 E 50.2267 N
Re: TTF to bitmap conversion needed!
PL version==============
Przypuszczalnie niewielkim nakładem mógłbym napisać gratis programik w Delphi, który na wejściu czytałby z pliku string i parametry fontu, natomiast na wyjściu zapisałby wymaganą macierz. Własciwy program musiałby wówczas:
a) zapisać w pliku dane (string+ font param)
b) uruchomić ten programik
c) odczekać sekundę lub dwie (dopóki nie powstanie plik z danymi macierzy)
d) wczytać macierz
Jest to oczywiscie sztukowanie które ani mi się podoba, ani go nie polecam, ale jak się nie ma co się lubi... Gdyby ta wersja zyskałaby akceptację to proszę o specyfikację formatu zapisu (x,y,color).
EN version==============
Presumably, a small effort I could write free applet in Delphi, which he would read the input file( string and font parameters), and the output would save the required matrix. The main program would then:
a) save the data(font string + param) in the file
b) run the applet
c) Wait a second or two (until the file with matrix will be created)
d) load the matrix from the file
It is of course that not a kind of patching I like it nor recommend it, but if you do not have what you like ... If this version would gain acceptance, please specify a format (x, y, color).
Przypuszczalnie niewielkim nakładem mógłbym napisać gratis programik w Delphi, który na wejściu czytałby z pliku string i parametry fontu, natomiast na wyjściu zapisałby wymaganą macierz. Własciwy program musiałby wówczas:
a) zapisać w pliku dane (string+ font param)
b) uruchomić ten programik
c) odczekać sekundę lub dwie (dopóki nie powstanie plik z danymi macierzy)
d) wczytać macierz
Jest to oczywiscie sztukowanie które ani mi się podoba, ani go nie polecam, ale jak się nie ma co się lubi... Gdyby ta wersja zyskałaby akceptację to proszę o specyfikację formatu zapisu (x,y,color).
EN version==============
Presumably, a small effort I could write free applet in Delphi, which he would read the input file( string and font parameters), and the output would save the required matrix. The main program would then:
a) save the data(font string + param) in the file
b) run the applet
c) Wait a second or two (until the file with matrix will be created)
d) load the matrix from the file
It is of course that not a kind of patching I like it nor recommend it, but if you do not have what you like ... If this version would gain acceptance, please specify a format (x, y, color).
Re: TTF to bitmap conversion needed!
Dzięki za chęć pomocy. Spróbuję jeszcze rozeznać temat, gdyż klient nie określił się do końca jaki chce format danych wyjściowych - chce programować matrycę LED (reklamową) zupełnie własnej konstrukcji, sam wymyślił sposób transmisji do niej oraz sposób przechowywania danych w sterowniku. Pogadam z nim i ew. skontaktuję się.
EN:
Thanks for help!
Marek
EN:
Thanks for help!
Marek
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: TTF to bitmap conversion needed!
Hello Marek,mol wrote:Does sb. have (and can share) example, how to convert truetype fonts to bitmap?
Eg. given string, the name of font and size converted to bitmap (or array of bits....)
I leave you here an example of the bits copy, I hope you find it useful.
Best Regards,
Claudio Soto.
Code: Select all
#include <hmg.ch>
Function Main
PRIVATE Text_Pixel1 := ""
PRIVATE Text_Pixel2 := ""
PRIVATE Font_Pixel := {}
PRIVATE Text := " Hello Marek "
* PRIVATE Text_Font := "Arial"
PRIVATE Text_Font := "Castellar"
PRIVATE Text_Size := 12
PRIVATE Text_y := 10
PRIVATE Text_x := 10
PRIVATE Text_Width := 140
PRIVATE Text_Height := 20
DEFINE WINDOW Form1;
AT 0,0;
WIDTH 640 HEIGHT 600;
TITLE 'COPY FONT' ;
MAIN;
ON PAINT Write ("Form1", Text_y, Text_x+250, BLUE)
@ Text_y ,Text_x LABEL Label_Text VALUE Text WIDTH Text_Width HEIGHT Text_Height FONT Text_Font SIZE Text_Size FONTCOLOR BLACK BACKCOLOR WHITE
@ 50, 10 EDITBOX Edit_box_1 VALUE "" WIDTH 600 HEIGHT 450 FONT "Courier" SIZE 10 READONLY
@ 520, 200 BUTTON Button_1 CAPTION "Read/Paste" ACTION Read_Paste ()
@ 520, 380 BUTTON Button_2 CAPTION "Font_Pixel1.Txt" ACTION {|| Form1.Edit_box_1.Value := Text_Pixel1}
@ 520, 500 BUTTON Button_3 CAPTION "Font_Pixel2.Txt" ACTION {|| Form1.Edit_box_1.Value := Text_Pixel2}
Form1.Button_2.Enabled := .F.
Form1.Button_3.Enabled := .F.
END WINDOW
CENTER WINDOW Form1
ACTIVATE WINDOW Form1
RETURN
*********************************************************************
Procedure Read_Paste
Read ("Form1", Text_y, Text_x, Text_Width, Text_Height)
Write ("Form1", Text_y, Text_x+250, BLUE)
Form1.Button_2.Enabled := .T.
Form1.Button_3.Enabled := .T.
Return
*********************************************************************
Procedure Read (WinName, y, x, Width, Height)
Local Flag := .F.
Local BackGroundColor := 0
Local Color := 0
Local i,k
hWnd = GetFormHandle (WinName)
Text_Pixel1 := ""
Text_Pixel2 := ""
Font_Pixel := ARRAY (Height, Width)
FOR i = 1 TO LEN (Font_Pixel)
FOR k = 1 TO LEN (Font_Pixel [1])
Color := GET_PIXEL (hWnd, x+k-1, y+i-1)
IF flag = .F.
flag = .T.
BackGroundColor = ACLONE (Color)
ENDIF
IF Color [1] = BackGroundColor [1] .AND. Color [2] = BackGroundColor [2] .AND. Color [3] = BackGroundColor [3]
Font_Pixel [i,k] := 0
Text_Pixel1 := Text_Pixel1 + "0"
Text_Pixel2 := Text_Pixel2 + " "
ELSE
Font_Pixel [i,k] := 1
Text_Pixel1 := Text_Pixel1 + "1"
Text_Pixel2 := Text_Pixel2 + "1"
ENDIF
NEXT
Text_Pixel1 := Text_Pixel1 +CHR(13)+CHR(10)
Text_Pixel2 := Text_Pixel2 +CHR(13)+CHR(10)
DO EVENTS
NEXT
MEMOWRIT("FONT_PIXEL1.TXT", Text_Pixel1)
MEMOWRIT("FONT_PIXEL2.TXT", Text_Pixel2)
Return
**********************************************************************
Procedure Write (WinName, y, x, color_text)
Local i,k
IF LEN (Font_Pixel) = 0
Return
ENDIF
hWnd = GetFormHandle (WinName)
FOR k = 1 TO LEN (Font_Pixel [1])
FOR i = 1 TO LEN (Font_Pixel)
IF Font_Pixel [i,k] <> 0
SET_PIXEL (hWnd, x+k-1, y+i-1, color_text [1], color_text [2], color_text [3])
ENDIF
NEXT
NEXT
Return
*#########################################################################################################################
* FUNCIONES EN C
*#########################################################################################################################
#pragma begindump
#include <windows.h>
#include "hbapi.h"
//*****************************************************************************
//* GET_PIXEL (hWND, x, y) ---> Return {R,G,B}
//*****************************************************************************
HB_FUNC (GET_PIXEL)
{
HWND hWnd;
HDC hDC;
COLORREF color;
int x,y;
if (hb_pcount() != 3 || hb_parinfo(1) != HB_IT_INTEGER || hb_parinfo(2) != HB_IT_INTEGER || hb_parinfo(3) != HB_IT_INTEGER)
{ hb_retni(-1);
return;
}
hWnd = (HWND) hb_parnl (1);
x = hb_parni(2);
y = hb_parni(3);
hDC = GetDC (hWnd);
color = GetPixel( hDC, x, y);
ReleaseDC (hWnd, hDC);
hb_reta( 3 );
hb_storvni((int) GetRValue(color), -1, 1 );
hb_storvni((int) GetGValue(color), -1, 2);
hb_storvni((int) GetBValue(color), -1, 3);
}
//**********************************************************************************
//* SET_PIXEL (hWND, x, y, R, G, B)
//**********************************************************************************
HB_FUNC (SET_PIXEL)
{
HWND hWnd;
HDC hDC;
int x,y;
BYTE R,G,B;
if (hb_pcount() != 6 || hb_parinfo(1) != HB_IT_INTEGER || hb_parinfo(2) != HB_IT_INTEGER || hb_parinfo(3) != HB_IT_INTEGER || hb_parinfo(4) != HB_IT_INTEGER || hb_parinfo(5) != HB_IT_INTEGER || hb_parinfo(6) != HB_IT_INTEGER)
{ hb_retni(-1);
return;
}
hWnd = (HWND) hb_parnl (1);
x = hb_parni(2);
y = hb_parni(3);
R = (BYTE) hb_parni(4);
G = (BYTE) hb_parni(5);
B = (BYTE) hb_parni(6);
hDC = GetDC (hWnd);
SetPixel( hDC, x, y, RGB (R,G,B));
ReleaseDC (hWnd, hDC);
}
#pragma enddump
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: TTF to bitmap conversion needed!
Great! It will be definitely useful.
Thanks Claudio
Thanks Claudio
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- Alex Gustow
- Posts: 290
- Joined: Thu Dec 04, 2008 1:05 pm
- Location: Yekaterinburg, Russia
- Contact:
Re: TTF to bitmap conversion needed!
Marek, do you must type so many symbols in "Polish version" of simple "Thanks..."?
Seriously, I remember that I saw something like this... I'll try to find (but I'm not sure that successfully).
As I understand, you want to have something like:
and after that use bit array in "oMyBMP" as (for example) captcha... or save this array to temporary (or constant) BMP-file... That's right?
P.S. I googled right now on "create captcha Foxpro" - and try to look here: "A Captcha Image Generator for Foxpro"... Maybe it helps?
P.P.S. (10 minutes later) While I thought, googleed and wrote my post - Claudio give us his sample. I'm too late again... Claudio, I tested it right now too - it's cool and useful thing! Thanks!
Seriously, I remember that I saw something like this... I'll try to find (but I'm not sure that successfully).
As I understand, you want to have something like:
Code: Select all
local oMyBMP
...
oMyBMP := String_2_BMP( "Marek Olszewski", "Times New Roman", 12 )
...
P.S. I googled right now on "create captcha Foxpro" - and try to look here: "A Captcha Image Generator for Foxpro"... Maybe it helps?
P.P.S. (10 minutes later) While I thought, googleed and wrote my post - Claudio give us his sample. I'm too late again... Claudio, I tested it right now too - it's cool and useful thing! Thanks!
Last edited by Alex Gustow on Thu May 20, 2010 1:42 pm, edited 1 time in total.
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: TTF to bitmap conversion needed!
Thanks Rathi, you're very kind.rathinagiri wrote:Great! It will be definitely useful.
Thanks Claudio
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: TTF to bitmap conversion needed!
Thanks Dr.srvet_claudio wrote: ...
I leave you here an example of the bits copy, I hope you find it useful.
...
Regards
--
Esgici
Viva INTERNATIONAL HMG
- srvet_claudio
- Posts: 2193
- Joined: Thu Feb 25, 2010 8:43 pm
- Location: Uruguay
- Contact:
Re: TTF to bitmap conversion needed!
You are welcome.esgici wrote:Thanks Dr.
Regards,
Claudio