Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 06-28-2020, 09:41 AM   #1
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default gfx.drawstr not working on Windows with string height above 255px

gfx.drawstr appears not to be working on Windows with string height (as returned by gfx.measurestr) greater than 255.

It works fine on Mac.

Is this a known bug?
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-28-2020, 10:39 AM   #2
White Tie
Pixel Pusher
 
White Tie's Avatar
 
Join Date: Mar 2007
Location: Blighty
Posts: 3,051
Default

It works for me.

Code:
gfx.init(bigasstext,1900,900)
gfx.setfont(1, "Verdana", 900)
gfx.drawstr("hello")
__________________
The House of White Tie
White Tie is offline   Reply With Quote
Old 06-29-2020, 05:58 AM   #3
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default Thank you for that response

Thank you @White Tie for the response. Yes, I see that gfx.drawstr works in that simplified context.

Please see this post https://forum.cockos.com/showthread.php?p=2311529 for a complete explanation of the problem including code example and LICEcap videos on both OS X and Windows.

Any thoughts?
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-29-2020, 06:38 AM   #4
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,648
Default

I have also come across this limit years ago when starting on the Stripper script (only use Windows here).

Never solved it - just limited text size to 255 in the script.

the fact that the actual limit is 255 suggests it may be a word length problem? Maybe windows/reaper is limiting the font size value to 8 bits under certain circumstances?
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is online now   Reply With Quote
Old 06-29-2020, 07:00 AM   #5
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

I agree @Ib0 that it must be related to some data structure that is one-byte (i.e. 0-255), but as @White Tie demonstrated it is not the gfx.drawstr function itself. The Lokasenna GUI software uses gfx.drawstr to render the text.

It does, however, render it to an off-screen buffer, and then later uses gfx.blit to display the already rendered image buffer on screen.

I wonder if this 255 limit applies only to gfx.drawstr when rendering to off-screen buffers? I will try to test that...
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-29-2020, 12:51 PM   #6
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default DEFINITE BUG: in gfx.drawstr

This code snippet demonstrates a bug in gfx.drawstr that occurs only on Windows and only when writing to an off-screen buffer.

If you set font size greater than 255 when writing to an off-screen buffer using gfx.drawstr, nothing gets written to the buffer.

LICEcap video below showing font sizes 255 and 256 with and without buffering.

@Schwa and @Justin, please fix.

Code:
usebuff=false
size=256

gfx.init("Test window",500,500,0,650,100)
gfx.set(255,255,255)
gfx.rect(0,0,500,500)

gfx.setfont(1, "Calibri", size)
local mf,w,h = math.floor,gfx.measurestr("001")
w,h = w+1,h+1
x,y = mf((500-w)/2),mf((500-h)/2)

if usebuff then
  gfx.dest = 1
  gfx.setimgdim(1,-1,-1)
  gfx.setimgdim(1, w, h)
end

gfx.set(0,0,0)
if not usebuff then gfx.x,gfx.y=x,y end
gfx.drawstr("001")

if usebuff then
  gfx.dest = -1
  gfx.blit(1,1,0,0,0,w,h,x,y,w,h,0,0)
end
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-29-2020, 02:32 PM   #7
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,909
Default

I have a workaround for you, but I'm afraid you're not going to like it:
  • On Windows, we use an alternate font rendering path for very large glyphs. In this case, the system font rendering trashes the alpha channel.
  • By default, gfx.blit() blits with alpha channel. You can disable this behavior by setting "gfx.mode=2" before calling gfx.blit().
Hope that helps!
Justin is offline   Reply With Quote
Old 06-29-2020, 02:41 PM   #8
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

I think I see what you mean now...

I will try and let you know, if that work around will work...
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-29-2020, 02:50 PM   #9
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 641
Default

Quote:
Originally Posted by Justin View Post
I have a workaround for you, but I'm afraid you're not going to like it:
  • On Windows, we use an alternate font rendering path for very large glyphs. In this case, the system font rendering trashes the alpha channel.
  • By default, gfx.blit() blits with alpha channel. You can disable this behavior by setting "gfx.mode=2" before calling gfx.blit().
Hope that helps!
Is this fixable in the first place or will this workaround be necessary for the future to come?
If the latter, I'll add that info to my Reaper-docs so they'll not get lost.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is offline   Reply With Quote
Old 06-29-2020, 02:56 PM   #10
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,909
Default

I don’t think this will be fixed, as doing so would have a significant performance penalty, though perhaps we can add a helper function to make it easier to fix alpha channels.
Justin is offline   Reply With Quote
Old 06-29-2020, 03:24 PM   #11
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

That doesn't appear to work. Can you be more specific please about the work around?

And in any case, will you fix the bug?
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-29-2020, 03:32 PM   #12
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

255px is not a large size compared to what all the operating systems and browsers handle. It is very common to need sizes in the 1000s of pixels especially in the audio profession where we need large take counters on screen for producers, engineers, and musicians to be able to see across the room (and many other uses...).

For Windows REAPER to be limited to 255px in this regard is very 1995!
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-29-2020, 03:36 PM   #13
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 641
Default

Quote:
Originally Posted by Justin View Post
I don’t think this will be fixed, as doing so would have a significant performance penalty, though perhaps we can add a helper function to make it easier to fix alpha channels.
^^^^^

@Justin

Ok, I'll add the information to my docs including a reference to your post.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish

Last edited by Meo-Ada Mespotine; 06-29-2020 at 03:42 PM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 06-29-2020, 03:56 PM   #14
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,909
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
^^^^^

@Justin

Ok, I'll add the information to my docs including a reference to your post.
Thanks for documenting this!
Justin is offline   Reply With Quote
Old 06-29-2020, 03:57 PM   #15
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,909
Default

Quote:
Originally Posted by cohler View Post
255px is not a large size compared to what all the operating systems and browsers handle. It is very common to need sizes in the 1000s of pixels especially in the audio profession where we need large take counters on screen for producers, engineers, and musicians to be able to see across the room (and many other uses...).

For Windows REAPER to be limited to 255px in this regard is very 1995!
It can draw larger sizes, it just doesn't correctly set the alpha channel.
Here is a modified version of your test script which works around the issue:
Code:
usebuff=true
size=256

gfx.init("Test window",500,500,0,650,100)
gfx.set(255,255,255)
gfx.rect(0,0,500,500)

gfx.setfont(1, "Calibri", size)
local mf,w,h = math.floor,gfx.measurestr("001")
w,h = w+1,h+1
x,y = mf((500-w)/2),mf((500-h)/2)

if usebuff then
  gfx.dest = 1
  gfx.setimgdim(1,-1,-1)
  gfx.setimgdim(1, w, h)
  gfx.mode = 2 -- ignore alpha channel
  gfx.blit(-1,1,0,x,y,w,h); -- copy background
end

gfx.set(0,0,0)
if not usebuff then gfx.x,gfx.y=x,y end
gfx.drawstr("001")

if usebuff then
  gfx.dest = -1
  gfx.mode = 2 -- ignore alpha channel
  gfx.blit(1,1,0,0,0,w,h,x,y,w,h,0,0)
end
If that isn't enough of an example, can you explain your use case (what are you drawing to the secondary bitmap and why, etc) in order to help you come up with a workaround?
Justin is offline   Reply With Quote
Old 06-29-2020, 08:24 PM   #16
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

Thanks for your response @Justin. I actually solved it just before I saw this post of yours, but your post is very helpful for future reference.

My actual use case is that I am using the Lokasenna GUI V2 to do a few windows in my software, so I had to figure out how to recode part of its Core.lua file and Label.lua class to handle this bug, which occurs only on Windows and only with a point size greater than 255.

Since I am using limited portions of Lokasenna GUI, however, I was able to fix it with relatively little coding.

Here's the problem as I first reported it in the Lokasenna thread: https://forum.cockos.com/showthread.php?p=2311529

It seems to me, however, that you should be able to fix this in the gfx.blit code and it would be worthwhile to do so IMHO.

Why would that cause any kind of performance hit? It's a 64-bit world these days, and there's essentially no limit on font size rendering in Windows as far as I can see.

Having a one-byte font size seems to be an antiquated architecture in any case.
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-30-2020, 04:51 AM   #17
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,909
Default

Quote:
Originally Posted by cohler View Post
It seems to me, however, that you should be able to fix this in the gfx.blit code and it would be worthwhile to do so IMHO.

Why would that cause any kind of performance hit? It's a 64-bit world these days, and there's essentially no limit on font size rendering in Windows as far as I can see.

Having a one-byte font size seems to be an antiquated architecture in any case.
The issue is not that the font size is represented by one byte -- the issue is that we use a different font rendering path for fonts with a size of 256 or higher, and in this path (win32 DrawTextW()) the alpha channel is set by the text rendererer to 0.

If we were to try to fix that path in gfx.drawstr(), it would involve postprocessing the rendered text, which would be extra work. And fixing in gfx.blit() is not possible, as once the text is rendered into the image the alpha channel is what it is! So live with it and use a workaround.

Save us all some time and stop telling us how to fix things that you don't understand.
Justin is offline   Reply With Quote
Old 06-30-2020, 07:44 AM   #18
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

Quote:
Originally Posted by Justin View Post
Save us all some time and stop telling us how to fix things that you don't understand.
No need to get testy. I understand quite well that gfx.drawstr() has an unnecessary BUG, that could be easily fixed. It is well-known that Windows GDI does not support alpha channel, but there are some equally well-known ways to address that.

In any case, since you are unwilling to fix this bug, I and others will continue to find work-arounds.

It would be nice if you would at least document the bug so that other people don't have to waste time on it as I did for the past three days.
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-30-2020, 10:12 AM   #19
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 641
Default

Quote:
Originally Posted by cohler View Post
In any case, since you are unwilling to fix this bug, I and others will continue to find work-arounds.
You can be pretty sure, if they could do it properly, they would do it. They're not unwillig but unable to do so. At least for the moment. Maybe things turn out to be fixable later, but not right now.

Quote:
It would be nice if you would at least document the bug so that other people don't have to waste time on it as I did for the past three days.
That's why I do docs at api.mespotine.de where I add such details if they come up and try to clear up possible confusions.

And, just an afterthought: what if no one knew about this bug until now? How could this be documented if no one knew that before?
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is offline   Reply With Quote
Old 06-30-2020, 10:28 AM   #20
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
You can be pretty sure, if they could do it properly, they would do it. They're not unwillig but unable to do so. At least for the moment. Maybe things turn out to be fixable later, but not right now.

That's why I do docs at api.mespotine.de where I add such details if they come up and try to clear up possible confusions.

And, just an afterthought: what if no one knew about this bug until now? How could this be documented if no one knew that before?
  1. Obviously, Justin knew all about it based on his quick and direct response. Furthermore, others posted about the problem previously as well (when I first posted, I received response from someone who ran into the same issue years ago). See https://forum.cockos.com/showthread.php?p=2311734 in this thread.
  2. Where would I or others find your documentation of the bug? I see no documentation of it at https://mespotin.uber.space/Ultrasch...ua_gfx.drawstr
  3. As Justin explained, the problem is that gfx.drawstr uses a Microsoft GDI function to render text above 255-points. The lack of support for the alpha channel in the Microsoft GDI is well-known. There are simple ways to address the problem, however, documented on many sites all over the Internet. Cockos evidently just doesn't want to do so.
  4. The OS X version of REAPER handles it correctly. There's no reason Windows version could not do so as well. They simply don't want to fix it.
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com

Last edited by cohler; 06-30-2020 at 10:32 AM. Reason: added post reference
cohler is offline   Reply With Quote
Old 06-30-2020, 11:07 AM   #21
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 3,193
Default

Quote:
Originally Posted by cohler View Post
There are simple ways to address the problem, however, documented on many sites all over the Internet. Cockos evidently just doesn't want to do so.
Then fix it yourself and provide a patch that improves the large-font branch. There's a bit of code in WDL's lice_textnew.cpp's LICE_CachedFont::​DrawTextImpl that appears to be suspiciously related.

Last edited by cfillion; 06-30-2020 at 11:31 AM.
cfillion is offline   Reply With Quote
Old 06-30-2020, 11:48 AM   #22
cohler
Human being with feelings
 
Join Date: Dec 2018
Posts: 240
Default

Quote:
Originally Posted by cfillion View Post
Then fix it yourself and provide a patch that improves the large-font branch. There's a bit of code in WDL's lice_textnew.cpp's LICE_CachedFont::​DrawTextImpl that appears to be suspiciously related.
I was not aware that the code was public domain, but thanks for pointing it out. I took a quick look and I see where the two relevant calls to DrawTextW are. If I get some free time in a few months, I may take a look at it. But REAPER is owned by Cockos, is it not? I would assume it would be to their financial benefit to fix their product right? I am very busy with several of my businesses at the moment.
__________________
Source-Destination 4-Point Editing for REAPER!
Available NOW for PC & Mac • FREE Trial License included
info@cohlerclassical.comhttps://cohlerclassical.com
cohler is offline   Reply With Quote
Old 06-30-2020, 02:26 PM   #23
Klangfarben
Human being with feelings
 
Join Date: Jul 2016
Location: Los Angeles, CA
Posts: 1,107
Default

Quote:
Originally Posted by cohler View Post
But REAPER is owned by Cockos, is it not? I would assume it would be to their financial benefit to fix their product right? I am very busy with several of my businesses at the moment.
Since you are clearly upset about Cockos' lack of bug fixes, perhaps now is an opportune time to strike out on your own and code a DAW that does everything you want. In between your multiple business ventures of course.
Klangfarben is online now   Reply With Quote
Old 06-30-2020, 06:50 PM   #24
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 641
Default

Quote:
Originally Posted by cohler View Post
  1. Obviously, Justin knew all about it based on his quick and direct response.
  1. But not knew, how to fix it properly(only with performance-loss). Otherwise, he would have done it already.
    Obviously.

    Quote:
  2. Where would I or others find your documentation of the bug? I see no documentation of it at https://mespotin.uber.space/Ultrasch...ua_gfx.drawstr
  3. Oh c'mon, I meant I add such issues to my docs when I come across them.
    And the one mentioned in here with Justin's workaround I added to my own sourcefiles just a few hours ago and release it, when I cleaned up some other stuff in the docs as well.
    Which will be...well...tomorrow.

    As if I had already documented everything before the fact...

    Quote:
  4. As Justin explained, the problem is that gfx.drawstr uses a Microsoft GDI function to render text above 255-points.
  5. The OS X version of REAPER handles it correctly. There's no reason Windows version could not do so as well.
You can't compare apples with windows. They are just the same planet, but not the same universe

Quote:
They simply don't want to fix it.
Or simply can't because of performance-issues caused by such a fix currently, as Justin pointed out.

Anyway, I'll return back to my stuff. I made my point, I think. Was just looking into the thread again for maybe some more helpful insights into the actual issue so that I could add to docs or make tools to deal with it properly.
But I think, this has been sorted out already and no new stuff emerging.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:54 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.