Recent

Author Topic: Make label text wider?  (Read 4569 times)

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Make label text wider?
« on: March 27, 2018, 04:28:46 pm »
There is a way to make text of TLabel wider, there is an option or I just need to change the font?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Make label text wider?
« Reply #1 on: March 27, 2018, 04:39:09 pm »
wider how? like bold? or bigger gap between the letters?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: Make label text wider?
« Reply #2 on: March 27, 2018, 04:48:45 pm »
wider how? like bold? or bigger gap between the letters?

Hi, like this attached image. Height is the same in both characters, the width is doubled in the second one.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Make label text wider?
« Reply #3 on: March 27, 2018, 05:10:21 pm »
looks like bold to me ee label.font.style := [fsBold];

EDIT:
If I'm off then the only way to accomplish that is either change the font size or use your own "painter" to stretch the letters. The default os API (textout etc) does not provide any abilities to arbitrary manipulate width of a sentence.
« Last Edit: March 27, 2018, 05:12:50 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: Make label text wider?
« Reply #4 on: March 27, 2018, 08:07:18 pm »
Hi, thanks. Seems that by default is not possible.

And no, is not bold, I stretched it to double width on a graphic design software, I think it was possible here too.

Maybe I need to use bitmaps for some glyphs instead of text.

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: Make label text wider?
« Reply #5 on: March 27, 2018, 11:13:55 pm »
Write to a Tbitmap that is smaller than the destination, then use the Canvas.StretchDraw.....
The only true wisdom is knowing you know nothing

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Make label text wider?
« Reply #6 on: March 28, 2018, 12:56:49 am »
Hi, thanks. Seems that by default is not possible.

And no, is not bold, I stretched it to double width on a graphic design software, I think it was possible here too.

Maybe I need to use bitmaps for some glyphs instead of text.
well in order to avoid writing a ttf/oft renderer the only two options that I know of are
1) draw to bitmap and stretchblt it to the required width somepixelation is expected
2) add the appropriate width of outline (has too many irregularities)
3) create an svg/emf imagelist that can be used to transform the images to anything with out pixelation :P 
sorry sorry got carried away a bit
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: Make label text wider?
« Reply #7 on: March 28, 2018, 03:01:09 am »
I already built an SVG viewer with BGRABitmap but is not retina display ready. Like almost all TBitmap TBGRABitmap or similar.

For that I was looking for another option.

But maybe you are right with the image list. I'm aware of the high DPI image list. That maybe can help me with this.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Make label text wider?
« Reply #8 on: March 28, 2018, 09:05:06 pm »
For that I was looking for another option.

Try CreateFontIndirect:
Code: Pascal  [Select][+][-]
  1. uses
  2.   LCLIntf;
  3. ...
  4.  
  5. procedure TForm1.FormPaint(Sender: TObject);
  6. var
  7.   ALogFont: TLogFont;
  8.   OldFont, OldMode: Integer;
  9.   WiderFont: HFONT;
  10.   s: string;
  11.   w: integer;
  12. begin
  13.   OldMode := SetBkMode(Canvas.Handle, TRANSPARENT);
  14.  
  15.   s := 'Some Text';
  16.   TextOut(Canvas.Handle, 10, 10, pchar(s), Length(s));
  17.  
  18.   OldFont := 0;
  19.  
  20.   if GetObject(Canvas.Font.Reference.Handle, SizeOf(ALogFont), @ALogFont) <> 0 then
  21.   begin
  22.     for w := 10 to 15 do
  23.     begin
  24.       ALogFont.lfWidth:=w;
  25.       WiderFont := CreateFontIndirect(ALogFont);
  26.       if WiderFont <> 0 then
  27.       begin
  28.         OldFont := SelectObject(Canvas.Handle, WiderFont);
  29.         s := Format('Some Text - %d ',[w]);
  30.         TextOut(Canvas.Handle, 10, 40+20*(w-10), pchar(s), Length(s));
  31.         if OldFont <> 0 then
  32.           DeleteObject(SelectObject(Canvas.Handle, OldFont));
  33.       end;
  34.     end;
  35.   end;
  36.  
  37.   SetBkMode(Canvas.Handle, OldMode);
  38. end;

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Make label text wider?
« Reply #9 on: March 28, 2018, 09:15:50 pm »
Unfortunately, it does not work on Qt.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Make label text wider?
« Reply #10 on: March 28, 2018, 10:31:45 pm »
Instead of writing in a bitmap and stretching to the desired length, it could be written in the correct length and then compressed to the correct height. The pixelisation should be much better this way.

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: Make label text wider?
« Reply #11 on: March 28, 2018, 11:13:41 pm »
Unfortunately, it does not work on Qt.
Yes, but LCLIntf also holds CreateFont() which should be cross-platform.
http://wiki.lazarus.freepascal.org/lclintf

No idea if the width parameter really does something on Qt.
On Win32 it redirects to CreateFontIndirect.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Make label text wider?
« Reply #12 on: March 29, 2018, 06:19:26 am »
Unfortunately, it does not work on Qt.
QT has setStretch:
Quote
Sets the stretch factor for the font.

The stretch factor changes the width of all characters in the font by factor percent. For example, setting factor to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The default stretch factor is 100. The minimum stretch factor is 1, and the maximum stretch factor is 4000.

Someone needs to add it to QFont class and use it in CreateFontIndirect. Or QFont_setStretch could be used directly.

 

TinyPortal © 2005-2018