mIRC Home    About    Download    Register    News    Help

Print Thread
#3414 25/12/02 04:41 AM
Joined: Dec 2002
Posts: 5
I
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Dec 2002
Posts: 5
I think I have found a problem with the results the $width identifyer returns for some fonts. With Verdana for example, //echo -a $width(This is a test,Verdana,10) returns 66. If you were to then create an image in photoshop say 66 pixels in width and add 'This is a test' size 10 normal Verdana to the image, the text would run outside the borders of the image because $width returned the wrong value.

I have created a small script to show this for users with mdx.dll

Code:
alias widthtest {
  set %_width $width(This is a test,$$1-,10)
  set %_text $$1-
  dialog -m _widthcheck _widthcheck
}

dialog _widthcheck {
  title "widthtest"
  size -1 -1 %_width 20
  button "ok", 45, 1 1 1 1,hide ok
  text "This is a test",1,0 0 %_width 20
}

on *:dialog:_widthcheck:init:0: {
  dll $mdx SetMircVersion $version 
  dll $mdx MarkDialog $dname
  dll $mdx SetFont $dname 1 -10 400 %_text
}


typing /widthtest Fixedsys shows a proper result while /widthtest Verdana shows the text being wrapped to the next line because $width reported a wrong value.

Some fonts other than Verdana which return wrong values are Times New Roman, Courier New, Modern, and I'm sure there's some others.

Thanks

#3415 25/12/02 11:25 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
One thing, you use set %_width $width(This is a test,$$1-,10) to get the width. And then use dll $mdx SetFont $dname 1 -10 400 %_text. Now, I've never really used mdx, but from that I'd assume -10 is the fontsize. -10 and 10 are different sizes. Try using $width(This is a test,$$1-,-10) and you get 87, which is most likely the correct width.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#3416 26/12/02 04:33 AM
Joined: Dec 2002
Posts: 5
I
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Dec 2002
Posts: 5
to start, thanks for the reply. The -10 is just the way mdx sets a font of 10.. strange but it's the way the readme says to do it.. having it as '10' actually makes the font a lot smaller with mdx. Also the correct width for the verdana test is about 71 (+5 from what $width reports). This can be seen in the photoshop method I listed at top.

Thanks again

Anyone else try this with mdx/photoshop?

#3417 26/12/02 04:36 AM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
I've been trying it with the same wierd results..

#3418 26/12/02 12:18 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Yeah, in mIRC anytime you use a font related function or identifer 10 would mean fontsize 10 pixels, whereas -10 means fontsize 10 points. Points is the measurement used by the Windows Font Dialog, and is generally what people are talking about when they refer to font sizes.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#3419 27/12/02 12:47 AM
Joined: Dec 2002
Posts: 5
I
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Dec 2002
Posts: 5
starbucks, I don't know if you see what I'm talking about, sorry if I'm just repeating what you already know.

Not considering MDX..
//echo -a $width(This is a test,Verdana,-10) returns 87 pixels. With an image of 87 pixels in width with text Verdana size 10 the text is too short:


//echo -a $width(This is a test,Verdana,10) returns 66 pixels. With an image of 66 pixels in width with text Verdana size 10 the text runs outside the image's borders:


//echo -a $width(This is a test,Fixedsys,10) returns 112 pixels. With an image of 112 pixels in width text fits:

#3420 27/12/02 10:08 PM
Joined: Dec 2002
Posts: 87
V
vcv Offline
Babel fish
Offline
Babel fish
V
Joined: Dec 2002
Posts: 87
immortal: re-read what he said.. if you put - in front, it makes it use POINTS and not PIXELS.. which are 2 different measurements for fonts.

#3421 27/12/02 11:05 PM
Joined: Dec 2002
Posts: 5
I
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Dec 2002
Posts: 5
I understand that. That is why I used both 10 an -10 for the two top images. One of those should of returned the correct value (-10) but none did.

EDIT: $width returns the number of pixels the text takes up, be in from fonts using points or pixels

Last edited by immortalnut; 27/12/02 11:12 PM.
#3422 28/12/02 01:33 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The problem is that while $width(This is a test,Verdana,-10) returns 87 pixels, this is actually 2 pixels bigger than the physical width of the font, and the way mIRC prints text using /drawtext (which is really what $width is made to be used with) that means a pixel either side of the text. Here's a picture showing what I mean:

Using the commands:
/drawrect @moo 7 1 200 200 87 30
/drawtext @moo 12 Verdana -10 200 200 This is a test

Both the rectangle and the text started from the exact same coordinate, yet the text fits perfectly inside the rectangle's borders because mIRC's /drawtext starts the actual text one pixel right of that and takes into account one pixel on the other side. This is probably why the width doesn't seem to add up in other applications - because you're aligning the edge of the text to the left and coming up 2 pixels short on what you expect.

As for the reason why Fixedsys has the same width using -10 and 10 it's because Fixedsys isn't a TrueType font and only has one size, no matter what size parameter you give $width with Fixedsys it will always give the same length for the text because it can only be displayed at that one size.


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard