PureBasic Forum
http://forums.purebasic.com/english/

Bug with fonts for StringGadgets?
http://forums.purebasic.com/english/viewtopic.php?f=5&t=71890
Page 1 of 2

Author:  Dude [ Sat Dec 08, 2018 6:43 am ]
Post subject:  Bug with fonts for StringGadgets?

[Edited title, because this bug only appears to occur with StringGadgets].

When I run this code, only the first StringGadget font is underlined, at size 17. The size 13 font doesn't get underlined, so it seems the underline only occurs with certain font sizes? The size 13 also doesn't underline if I use the #PB_Font_HighQuality flag.

I note that Paint Shop Pro (bottom image) does underline size 13 though, so I assume this might be a PureBasic bug?

Code:
OpenWindow(0,200,200,350,120,"test",#PB_Window_SystemMenu)

StringGadget(1,10,10,330,35,"This is underlined")
SetGadgetFont(1,LoadFont(1,"@DFPOP1-W12",17,#PB_Font_Underline))

StringGadget(2,10,70,330,35,"But this isn't. Why?")
SetGadgetFont(2,LoadFont(2,"@DFPOP1-W12",13,#PB_Font_Underline))

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Image

Image

Author:  Little John [ Sat Dec 08, 2018 8:15 am ]
Post subject:  Re: Bug with LoadFont?

Which operating system and which PB version did you use?

When running your above code with my computer on Windows 10, using PB 5.62 (x64) or PB 5.70 beta 3 (x64), the text in both StringGadgets is underlined, as expected.

Author:  Dude [ Sat Dec 08, 2018 8:21 am ]
Post subject:  Re: Bug with LoadFont?

I'm using Win 7 Ultimate (64-bit) with PureBasic 5.70 beta 2 (32-bit). Obviously a bug then, between versions.

Author:  breeze4me [ Sat Dec 08, 2018 8:42 am ]
Post subject:  Re: Bug with LoadFont?

The same problem here, using PB 5.70 beta 3 x64/x86 on Windows 10 home rs5(1809) x64 Korean.

It seems to occur when the vertical size of a font is 1 2 5 6 7 12 13.

Author:  ccode [ Sat Dec 08, 2018 5:14 pm ]
Post subject:  Re: Bug with LoadFont?

Hello Dude!

Fonts sometimes behave mysteriously.

Code:
;Windows Bug ?

;Under Windows, it no longer works with font sizes: (1 2 4 5 6 7 11 12 13 18 .....)

;For whatever reason ?

;Font-URL: https://www.fontyukle.net/en/DFPOP1-W12.ttf

;It could be tested on Mac.
;(Please adjust)
;(I do not have a Mac)

Global Test_FontSize.i = 18

OpenWindow(0,200,200,400,140,"test",#PB_Window_SystemMenu)

;StringGadget(1,10,10,380,50,"")
EditorGadget(1,10,10,380,50)
SetGadgetText(1,"This is underlined")

;StringGadget(2,10,70,380,50,"")
EditorGadget(2,10,70,380,50)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  SetGadgetText(2,"And that is also underlined (under Linux)")
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
  If FindString("1 2 4 5 6 7", Str(Test_FontSize)) Or Test_FontSize = 11 Or Test_FontSize = 12 Or Test_FontSize = 13 Or Test_FontSize = 18 ;......
    SetGadgetText(2,"But this isn't. Why?")
  Else
    SetGadgetText(2,"And that is also underlined (under Windows)")
  EndIf
CompilerEndIf

SetGadgetFont(1,LoadFont(1,"DFPOP1-W12",17,#PB_Font_Underline))
SetGadgetFont(2,LoadFont(2,"DFPOP1-W12",Test_FontSize,#PB_Font_Underline))

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  CompilerIf Subsystem("qt")
    QtScript(~"gadget(1).styleSheet = \"text-decoration: underline\" ")
    QtScript(~"gadget(2).styleSheet = \"text-decoration: underline\" ")
  CompilerElse
    Enumeration
      #PANGO_UNDERLINE_NONE
      #PANGO_UNDERLINE_SINGLE
      #PANGO_UNDERLINE_DOUBLE
      #PANGO_UNDERLINE_LOW
      #PANGO_UNDERLINE_ERROR
    EndEnumeration
    ImportC ""
      gtk_entry_set_attributes(*entry, *attrList)
      pango_attr_underline_new(underline.l)
      pango_attr_list_insert(*attrList, *attr.PangoAttribute)
      pango_attr_list_new()
    EndImport
    If PeekS(gtk_widget_get_name_(GadgetID(1)), -1, #PB_UTF8) = "GtkEntry"
      ;StringGadget 1
      *attrList = pango_attr_list_new()
      *underline.PangoAttribute = pango_attr_underline_new(#PANGO_UNDERLINE_SINGLE)
      pango_attr_list_insert(*attrList, *underline)
      gtk_entry_set_attributes(GadgetID(1), *attrList)
    EndIf
    If PeekS(gtk_widget_get_name_(GadgetID(2)), -1, #PB_UTF8) = "GtkEntry"
      ;StringGadget 2
      *attrList = pango_attr_list_new()
      *underline.PangoAttribute = pango_attr_underline_new(#PANGO_UNDERLINE_SINGLE)
      pango_attr_list_insert(*attrList, *underline)
      gtk_entry_set_attributes(GadgetID(2), *attrList)
    EndIf
    If PeekS(gtk_widget_get_name_(GadgetID(1)), -1, #PB_UTF8) = "GtkTextView" Or PeekS(gtk_widget_get_name_(GadgetID(2)), -1, #PB_UTF8) = "GtkTextView"
      Define.GtkWidget *gTextView1, *gTextView2
      Define.GtkTextBuffer *gBuffer1, *gBuffer2
      Define.GtkTextIter s_iter, e_iter
     
      *gTextView1 = GadgetID(1) : *gTextView2 = GadgetID(2)
      *gBuffer1 = gtk_text_view_get_buffer_(*gTextView1) : *gBuffer2 = gtk_text_view_get_buffer_(*gTextView2)
      gtk_text_buffer_create_tag_(*gBuffer1, "underline", "underline", #PANGO_UNDERLINE_SINGLE)
      gtk_text_buffer_create_tag_(*gBuffer2, "underline", "underline", #PANGO_UNDERLINE_SINGLE)
      gtk_text_buffer_get_bounds_(*gBuffer1, @s_iter, @e_iter)
      gtk_text_buffer_apply_tag_by_name_(*gBuffer1, "underline", @s_iter, @e_iter)
      gtk_text_buffer_get_bounds_(*gBuffer2, @s_iter, @e_iter)
      gtk_text_buffer_apply_tag_by_name_(*gBuffer2, "underline", @s_iter, @e_iter)
    EndIf
  CompilerEndIf
CompilerEndIf

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Author:  Dude [ Sun Dec 09, 2018 2:12 am ]
Post subject:  Re: Bug with LoadFont?

ccode wrote:
Fonts sometimes behave mysteriously

Hmm, yes, it appears to work correctly with EditorGadgets in your example, but not with StringGadgets as per my example. Title edited in my first post to reflect this.

Author:  ccode [ Sun Dec 09, 2018 10:09 am ]
Post subject:  Re: Bug with fonts for StringGadgets?

Dude wrote:
Hmm, yes, it appears to work correctly with EditorGadgets in your example, but not with StringGadgets as per my example. Title edited in my first post to reflect this.


Under Windows, it no longer works with font sizes: ( 1 2 4 5 6 7 11 12 13 18 ..... ).

Windows Bug ?

Author:  Dude [ Sun Dec 09, 2018 12:15 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

ccode wrote:
This has nothing to do with the gadget.

StringGadget or EditorGadget does not matter.

Under Windows, it no longer works with font sizes <= 13.0

Well, my experience differs. If I use the font with size <=13 with StringGadgets (say: 10), then it's NOT underlined for StringGadgets; but size 10 IS underlined for EditorGadgets. This is using your own code above and commenting/uncommenting the gadgets as required for testing. So for me, it is a gadget issue.

Author:  ccode [ Sun Dec 09, 2018 12:24 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

Hi Dude! :mrgreen:

This is even more mysterious.

Quote:
for StringGadgets; but size 10 IS underlined for EditorGadgets

You're right!

It seems to occur when the vertical size of a font is 1 2 4 5 6 7 11 12 13 18 ....

Under Linux, it works.

Author:  #NULL [ Sun Dec 09, 2018 12:59 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

I don't know if this is related but when using editor Geany in Linux I sometimes don't see underscores, i.e. they look like spaces and become visiblibe when changing the zoom or font size. This also depends on the Font used. I guess it's a similar rendering issue(?)

Author:  ccode [ Sun Dec 09, 2018 1:22 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

Quote:
I don't know if this is related but when using editor Geany in Linux I sometimes don't see underscores, i.e. they look like spaces and become visiblibe when changing the zoom or font size. This also depends on the Font used. I guess it's a similar rendering issue(?)


Hello #Null!

How can I check this ?
I only occasionally see rendering problems that seem to be related to the GPU and the use of OpenGL in text rendering.

Author:  #NULL [ Sun Dec 09, 2018 1:42 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

@ccode
I can't reproduce it now. I think it was this site that helped me at the time. I did not remember that they said it was a font bug in that case (maybe fixed by now) but maybe that's true for DFPOP1-W12 as well. Anyway an underscore is an actual character where underline is probably done differently, i don't really know.

Author:  ccode [ Sun Dec 09, 2018 2:26 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

You have to experiment with the "character set" -parameters and the "output precision" -parameters.

After that you are smarter;)

Code:
;....
;StringGadget(2,10,70,380,50,"")
EditorGadget(2,10,70,380,50)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  SetGadgetText(2,"And that is also underlined (under Linux)")
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
  If FindString("1 2 4 5 6 7", Str(Test_FontSize)) Or Test_FontSize = 11 Or Test_FontSize = 12 Or Test_FontSize = 13 Or Test_FontSize = 18 ;......
    SetGadgetText(2,"But this isn't. Why?")
  Else
    SetGadgetText(2,"And that is also underlined (under Windows)")
  EndIf
;   hf = CreateFont_( 13, 0, 0, 0, 0, 1, 1, 0, #DEFAULT_CHARSET, #OUT_TT_PRECIS, #CLIP_DEFAULT_PRECIS, #PROOF_QUALITY, #DEFAULT_PITCH, @"DFPOP1-W12")
 
  hf = CreateFont_( 13, 0, 0, 0, 0, 0, 1, 0, #SHIFTJIS_CHARSET, #OUT_TT_PRECIS, #CLIP_DEFAULT_PRECIS, #PROOF_QUALITY, #DEFAULT_PITCH, @"DFPOP1-W12")
CompilerEndIf


SetGadgetFont(1,LoadFont(1,"DFPOP1-W12",17,#PB_Font_Underline))
SetGadgetFont(2,hf) ; Look here !

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  CompilerIf Subsystem("qt")
;....


https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createfontw

Author:  Fred [ Mon Dec 10, 2018 8:20 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

I don't think it's a PB issue, but mostlikely a Windows one. We don't use separate code path for Windows 10 or Windows 7, so it should behave the same. On Windows on my computer it display both with underline.

Author:  ccode [ Mon Dec 10, 2018 9:12 pm ]
Post subject:  Re: Bug with fonts for StringGadgets?

I also do not see it as a bug.
One can easily make special adjustments (for special cases (for example, certain Japanese fonts)) with the Windows Api directly.

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/