Solved

Generating outline/vector fonts

Posted on 2006-07-11
8
412 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wininet read php file from internet issue 6 80
Simple Delphi Question 9 83
Delphi IDE crash without error message ... 7 74
Delphi inherited method 6 60
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

943 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

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now