Post Reply 
TEXTOUT_P : width ?
10-03-2015, 05:42 PM
Post: #5
RE: TEXTOUT_P : width ?
(10-03-2015 08:56 AM)komame Wrote:  I created a function that calculates the width (in pixels) of the text, but it is not very useful, because it is very slow.
However, I believe that it is possible to optimize and significantly speed up. I have some ideas.

Code:
TEXT_P_W();

EXPORT TEXT_WIDTH()
BEGIN
local width; 
 PRINT();
 width:=TEXT_P_W("ABC abc 123",1);
 PRINT(width);
 width:=TEXT_P_W("ABC abc 123",3);
 PRINT(width);
 width:=TEXT_P_W("ABC abc 123",7);
 PRINT(width);
END;

TEXT_P_W(t,s)
BEGIN
 local x,y;
 DIMGROB(G9,320,40);
 TEXTOUT_P(t,G9,0,0,s);
 FOR x FROM 319 DOWNTO 0 DO
  FOR y FROM 0 TO 39 DO
   IF(GETPIX_P(G9,x,y)≠#FFFFFF) THEN
    RETURN x;
   END;
  END;
 END;
END;

function TEXT_P_W(t,s), where:
t - the text to calculate width
s - font size

Having fixed fonts maybe is faster just having an array with the known char widths per font size

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
TEXTOUT_P : width ? - primer - 10-02-2015, 08:41 AM
RE: TEXTOUT_P : width ? - xset - 10-02-2015, 09:17 AM
RE: TEXTOUT_P : width ? - komame - 10-02-2015, 12:51 PM
RE: TEXTOUT_P : width ? - komame - 10-03-2015, 08:56 AM
RE: TEXTOUT_P : width ? - eried - 10-03-2015 05:42 PM
RE: TEXTOUT_P : width ? - komame - 10-03-2015, 07:45 PM
RE: TEXTOUT_P : width ? - komame - 10-04-2015, 04:21 PM
RE: TEXTOUT_P : width ? - primer - 10-05-2015, 03:04 PM
RE: TEXTOUT_P : width ? - Tyann - 10-12-2015, 11:58 AM
RE: TEXTOUT_P : width ? - hpfx - 10-14-2015, 10:02 PM



User(s) browsing this thread: 1 Guest(s)