Solved

Generating outline/vector fonts

Posted on 2006-07-11
8
409 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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…
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…

708 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

11 Experts available now in Live!

Get 1:1 Help Now