Solved

Generating outline/vector fonts

Posted on 2006-07-11
8
429 Views
Last Modified: 2013-12-03
Hi,
I'm trying to develop an application that will enable the user to insert some text on a canvas - the problem is this - the text needs to be a filled vector, i.e. the text needs to be an outline and instead of a black fill, the fill needs to be a series of lines. Further, the user should be able to move the text around on the screen - i.e. resize it or change its position.
Thanks
0
Comment
Question by:crav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 17086584
You can draw such a text like this

  PaintBox1.Canvas.Pen.Color := clBlack;
  PaintBox1.Canvas.Brush.Style := bsClear;

  BeginPath(PaintBox1.Canvas.Handle);
  PaintBox1.Canvas.Font.Size := 60;
  PaintBox1.Canvas.TextOut(5,5, 'ABAK');
  EndPath(PaintBox1.Canvas.Handle);


  PaintBox1.Canvas.Brush.Color := clRed;
  PaintBox1.Canvas.Brush.Style := bsBDiagonal;
  StrokeAndFillPath(PaintBox1.Canvas.Handle);
0
 

Author Comment

by:crav
ID: 17088374
not quite what I was after - the ulterior motive is to be able to output the text / object to CNC (vector) device, which is why the text or object needs to have a 'line' fill and needs to be able to move around the screen. I tried the code above, however i found that the text wouldnt even show up on the screen. When i commented out the lines  BeginPath(PaintBox1.Canvas.Handle); and  EndPath(PaintBox1.Canvas.Handle); the text showed up, but it was black filled text as opposed to a vector filled text.
Thanks
0
 
LVL 17

Expert Comment

by:mokule
ID: 17090879
If You need to output outline of text to CNC here is working example.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
  private
    { Private declarations }
    bmp : TBitmap;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  pt: array of TPoint;
  t: array of byte;
  Count: integer;
  i: integer;
begin
  with bmp.Canvas do
    begin
    Pen.Color := clBlack;
    Pen.Style := psSolid;
    Brush.Style := bsClear;

      Font.Name:='Arial';
      Font.Size:=48;

    BeginPath(Handle);
    TextOut(5,5, 'ABAK');
    EndPath(Handle);


    Brush.Color := clRed;
  //  bmp.Canvas.Brush.Style := bsBDiagonal;
  //  StrokeAndFillPath(bmp.Canvas.Handle);


    FlattenPath(Handle);

    Count := GetPath(Handle,pt,t,0);
    if Count > 0 then
      begin
      SetLength(pt,Count);
      SetLength(t,Count);
      if GetPath(Handle,pt[0],t[0],Count) >= 0 then
        begin
        for i := 0 to Count - 1 do
          begin
          Memo1.Lines.Add(IntToStr(pt[i].X) + ',' + IntToStr(pt[i].Y) + ','+ IntToStr(t[i]));
          case t[i] of
            PT_MOVETO: MoveTo(pt[i].X,pt[i].Y);
            PT_LINETO: LineTo(pt[i].X,pt[i].Y);
            else
              LineTo(pt[i].X,pt[i].Y);
            end;
          end;
        end
      end;
    end;

    PaintBox1.Invalidate;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bmp := TBitmap.Create;
  bmp.Width := PaintBox1.Width;
  bmp.Height := PaintBox1.Height;
  bmp.PixelFormat := pf24bit;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  PaintBox1.Canvas.Draw(0,0,bmp);
end;

end.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:crav
ID: 17093780
yes this achieves the desired result,
1> any suggestions on how the user might be able to move the text on the screen on run-time?
2> where might i find more info on this topic - i've scanned my delphi books cover to cover without to much luck...

thanks
0
 
LVL 17

Expert Comment

by:mokule
ID: 17102085
If You mean Path functions I've used You can look at msdn
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/paths_5g8j.asp
0
 
LVL 17

Accepted Solution

by:
mokule earned 100 total points
ID: 17102390
I've done some modificatiions for text moving.
To make it more pro You should add some markers allowing text widenning, rotation, etc

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    bmp : TBitmap;
    xc,yc: integer;
    xp,yp: integer;
    procedure DrawOutlineText(x, y: integer; str: string);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  xc := 0;
  yc := 0;
  DrawOutlineText(xc,yc,'ABAK');
end;

procedure TForm1.DrawOutlineText(x,y: integer; str: string);
var
  pt: array of TPoint;
  t: array of byte;
  Count: integer;
  i: integer;
begin
  with bmp.Canvas do
    begin
    Brush.Color := RGB(240,240,150);
    FillRect(Rect(0,0,bmp.Width,bmp.Height));

    Pen.Color := clBlack;
    Pen.Style := psSolid;
    Brush.Style := bsClear;

    Font.Name:='Arial';
    Font.Size:=48;

    BeginPath(Handle);
    TextOut(x,y, str);
    EndPath(Handle);


    Brush.Color := clRed;
  //  bmp.Canvas.Brush.Style := bsBDiagonal;
  //  StrokeAndFillPath(bmp.Canvas.Handle);


    FlattenPath(Handle);

    Count := GetPath(Handle,pt,t,0);
    if Count > 0 then
      begin
      SetLength(pt,Count);
      SetLength(t,Count);
      if GetPath(Handle,pt[0],t[0],Count) >= 0 then
        begin
        for i := 0 to Count - 1 do
          begin
//          Memo1.Lines.Add(IntToStr(pt[i].X) + ',' + IntToStr(pt[i].Y) + ','+ IntToStr(t[i]));
          case t[i] of
            PT_MOVETO: MoveTo(pt[i].X,pt[i].Y);
            PT_LINETO: LineTo(pt[i].X,pt[i].Y);
            else
              LineTo(pt[i].X,pt[i].Y);
            end;
          end;
        end
      end;
    end;

    PaintBox1.Invalidate;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  bmp := TBitmap.Create;
  bmp.Width := PaintBox1.Width;
  bmp.Height := PaintBox1.Height;
  bmp.PixelFormat := pf24bit;
  Form1.DoubleBuffered := true;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  PaintBox1.Canvas.Draw(0,0,bmp);
end;

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  xp := X;
  yp := Y;
end;

procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if ssLeft in Shift then
    begin
    xc := xc + x - xp;
    yc := yc + y - yp;
    DrawOutlineText(xc,yc,'ABAK');
    PaintBox1.Repaint;
    xp := X;
    yp := Y;
    end;
end;

end.
0
 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 25 total points
ID: 17104931
hello crav, , I have done many programs that have many text "Editing" methods, as in moving text blocks and resizing text blocks, you might look at these EE Questions to see if they might help you some -->

  http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20682653.html

  http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21024632.html

  http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20619562.html

I have not tried to do an "Hollow" non-filled text, but using a TMetaFile is a good way to have a "Movable" text block
0
 

Author Comment

by:crav
ID: 17107569
Thank you for your efforts - exactly what i was after...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month4 days, 23 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question