Solved

Generating outline/vector fonts

Posted on 2006-07-11
8
415 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
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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 33

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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