Recent

Author Topic: Is there an easy way to set a synedit box size based on font size ??  (Read 7219 times)

wpflum

  • Sr. Member
  • ****
  • Posts: 287
I'm in the beginnings of writing a terminal emulator and I need to make sure that the synedit box is exactly  80 columns by 24 rows (vt220 specification) no matter what size or type font is used.  Is there a simple way to do this??
« Last Edit: August 19, 2011, 04:01:56 pm by wpflum »

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: Is there an easy way to set a synedit box size based on font size ??
« Reply #1 on: August 22, 2011, 03:17:00 pm »
Hello, Hello, Is this thing on...  :D

Leave it to me to come up with something that no one else has ever tried before  :P

I've been playing around with using the canvas and font options on the synedit component but nothing seems to work the way I think it should.  Is there another type of object I can use as a basis for an adjustable screen/window instead of the synedit that would allow me to do what I'm looking for or should I maybe be looking at this in reverse and setting the font size to make it fit in whatever box size chosen???

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Is there an easy way to set a synedit box size based on font size ??
« Reply #2 on: August 22, 2011, 04:08:22 pm »
You could just write your own custom control descending from TCustomControl. That's what I would do.

Although you might want to search for this, maybe someone already wrote such a console control.

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Is there an easy way to set a synedit box size based on font size ??
« Reply #3 on: August 22, 2011, 04:35:20 pm »
It is easy enough to stretch the width and height of the component (plus the size of the form in which it sits, but the main problem will be to determine what the new sizes should be.  And that depends on the size of a character in the font you are using.

Trouble is that these are not always the same.  characters in 10pt "Courier New" do not have the same size as characters in 10pt "Lucida Typewriter" or even 10 pt "Courier".  It frequently comes close, but not quite.

I'm afraid I don't have a clear answer for you but the question - I assume - boils down to getting to know what the size of the bounding box around a character is in each font file.  Then you can derive the overall screen size from there.

Luckily you are writing a terminal emulator, so you will probably be limited to non-proportional fonts.  With proportional fonts it's much more difficult.
1.0/2.6.0  XP SP3 & OS X 10.6.8

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: Is there an easy way to set a synedit box size based on font size ??
« Reply #4 on: August 22, 2011, 05:44:18 pm »
It is easy enough to stretch the width and height of the component (plus the size of the form in which it sits, but the main problem will be to determine what the new sizes should be.  And that depends on the size of a character in the font you are using.

Trouble is that these are not always the same.  characters in 10pt "Courier New" do not have the same size as characters in 10pt "Lucida Typewriter" or even 10 pt "Courier".  It frequently comes close, but not quite.

I'm afraid I don't have a clear answer for you but the question - I assume - boils down to getting to know what the size of the bounding box around a character is in each font file.  Then you can derive the overall screen size from there.

Luckily you are writing a terminal emulator, so you will probably be limited to non-proportional fonts.  With proportional fonts it's much more difficult.

Yea, Non-Pro fonts only.  The issue with the font sizes are being a problem, even using the Canvas or Font object in the synedit box is not giving me what I need.  I'm starting out from scratch after a bit of playing with some other code and I'd thought it be nice to start out with a box that auto sizes so the end user could pick what font he/she wants from any non-proportional fonts on the machine but it looks like I'll just have to limit it to specific fonts with pedigrees  I've already checked out.  Bummer  :'(

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Is there an easy way to set a synedit box size based on font size ??
« Reply #5 on: August 22, 2011, 05:47:05 pm »
This might help, but I haven't tried it.

X:= Memo1.Font.GetTextWidth(Memo1.Lines);
Lazarus Trunk / fpc 2.6.2 / Win32

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Is there an easy way to set a synedit box size based on font size ??
« Reply #6 on: August 23, 2011, 09:48:12 am »
That sounds like a good idea Avishai.
Funny thing is that - at least on Windows - this function (and also the accompanying GetTextHeight)  always returns the value 16, irrespective of how small or large the text in the memo is.

Worst case would be to use just one single fixed font type (i.e. do not allow the user to choose a font) and then work with hard coded values. 
Terrible   ... It always makes me think  "come on! this is 2011".
1.0/2.6.0  XP SP3 & OS X 10.6.8

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12108
  • Debugger - SynEdit - and more
    • wiki
Re: Is there an easy way to set a synedit box size based on font size ??
« Reply #7 on: August 23, 2011, 11:03:58 am »
SynEdit has CharWidth and LineHeight property, that tells you the width/height of a single char. So you can calculate the space needed..

As for limiting the input, I would assume you handle keydown/Up/Press yourself (so you can handle special chars, escape sequences, etc), and modify the text with TextBetweenPoints[Point(75,2),Point(76,2)] := 'a';

So no line is allowed to have more than 80 chars ever.

You can control, if scrollbars should be shown, if the text does not fit in the component's space.
I suggest to pre-fill the 25x80 with spaces (and disable trim-trailing-spaces), so the scrollbars will not depend on content.

Also disable eoScrollPastEol from Options.

If you do not want scrollbars, you can modify the font size by trial and error....
If you want the x/y ratio changed, you can add spacing via ExtraCharSpacing and ExtraLineSpacing. Negative values allowed too, but may no look very good.

And then add something like a PositionHighlighter (see examples/synedit folder in your lazarus dir)

 

TinyPortal © 2005-2018