• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

Generating outline/vector fonts

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
crav
Asked:
crav
  • 4
  • 3
2 Solutions
 
mokuleCommented:
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
 
cravAuthor Commented:
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
 
mokuleCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
cravAuthor Commented:
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
 
mokuleCommented:
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
 
mokuleCommented:
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
 
Slick812Commented:
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
 
cravAuthor Commented:
Thank you for your efforts - exactly what i was after...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now