It is currently December 6th, 2022, 2:07 pm

String Meter "ClipString" not working correctly

Report bugs with the Rainmeter application and suggest features.
Frasier
Posts: 7
Joined: August 10th, 2012, 3:38 pm

String Meter "ClipString" not working correctly

Post by Frasier »

Hi!

The ClipString = 1 parameter for String Meters is not working correctly. E.g. for this string

"Abc defg.higt.joijw.efwef.efwef-wefwef.wefwef.wedd"
|------------------------------------------------| (this is the width of the meter)

the string is clipped to
"Abc..."

Correct (and much better, of course) would be:
"Abc defg.higt.joijw.efwef.efwef-wef..."

Please fix this.

Thanks!
User avatar
tass_co
Posts: 429
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: String Meter "ClipString" not working correctly

Post by tass_co »

Frasier wrote: September 28th, 2022, 7:38 am Hi!

The ClipString = 1 parameter for String Meters is not working correctly. E.g. for this string

"Abc defg.higt.joijw.efwef.efwef-wefwef.wefwef.wedd"
|------------------------------------------------| (this is the width of the meter)

the string is clipped to
"Abc..."

Correct (and much better, of course) would be:
"Abc defg.higt.joijw.efwef.efwef-wef..."

Please fix this.

Thanks!
Can you share your current code so we can help better?

Or

You must specify the width you want to be cut.
sample Width=200

ClipString

Code: Select all

[MeterText]
Meter=String
X=0
Y=10R
W=200
H=50
FontColor=197,252,223,255
FontSize=14
FontWeight=700
ClipString=1
AntiAlias=1
Text="This text will wrap due to ClipString=1"
I don't know where i going from here, but i promise it won't be boring... :great:
User avatar
balala
Rainmeter Sage
Posts: 14766
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: String Meter "ClipString" not working correctly

Post by balala »

Frasier wrote: September 28th, 2022, 7:38 am Please fix this.
tass_co is right here. Probably there is nothing to fix, because the ClipString is a long-used option and it does work. The only thing you have to take care is to set the proper size of the meter on which it is used. For instance:

Code: Select all

[MeterText]
Meter=STRING
X=0
Y=0
W=200
ClipString=1
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Abc defg.higt.joijw.efwef.efwef-wefwef.wefwef.wedd
See the width set to W=200. What you get with this option is this:
Text1.png
For this FontSize (FontSize=8), we get what did you post for example for W=30:
Text2.png
But changing the FontSize you have to change the value of the W option as well, in order to get the string clipped same way.
So, for first as tass_co asked, please post a code.
You do not have the required permissions to view the files attached to this post.
Frasier
Posts: 7
Joined: August 10th, 2012, 3:38 pm

Re: String Meter "ClipString" not working correctly

Post by Frasier »

Hi!

Sorry, but you are incorrect - there is indeed a bug with the clipping!

Example:

Code: Select all

Meter=STRING
X=10
Y=10r
W=190
H=14
ClipString=1
FontFace=Segoe UI
FontColor=220,220,220
FontSize=10
StringStyle=BOLD
StringAlign=LEFT
Text=D: New Order: 1x CarWashWax - Fillversion1234
produces the correct result:
correct.png
but if I just add 1 character (or more) to the text:

Code: Select all

Meter=STRING
X=10
Y=10r
W=190
H=14
ClipString=1
FontFace=Segoe UI
FontColor=220,220,220
FontSize=10
StringStyle=BOLD
StringAlign=LEFT
Text=D: New Order: 1x CarWashWax - Fillversion12345
it clips incorrectly:
incorrect.png


Why? This definitely needs fixing...

Thanks!
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2178
Joined: March 23rd, 2015, 5:26 pm

Re: String Meter "ClipString" not working correctly

Post by SilverAzide »

Frasier wrote: October 21st, 2022, 11:23 am Why? This definitely needs fixing...
The Rainmeter devs might need to comment, but I don't think this is fixable. Rainmeter uses Windows/DirectX APIs to do this clipping, and your string has some strange combination of font, font size, and meter width that is throwing off whatever logic is handling the clipping. If you slightly adjust the text, the meter width, etc., it will start working. But as you say, adding even a single character at the end throws everything off.

I don't have a proper solution for you, but if you want a very lame workaround that will definitely break any string exactly at the maximum width of the meter, you can do the following. Clipping works by breaking text at word boundaries (if any exist, like spaces, tabs, etc), so this trick works by substituting the spaces in a string with another character, eliminating the boundaries and forcing the clipping logic to break at characters instead of words. (Note that using non-breaking space characters does not work.)

Code: Select all

[MeasureString]
Measure=String
String="D: New Order: 1x CarWashWax - Fillversion1234"
Substitute=" ":"_"

[MeterTest]
Meter=String
MeasureName=MeasureString
X=10
Y=10r
W=190
H=18
ClipString=1
FontFace=Segoe UI
FontColor=220,220,220
FontSize=10
SolidColor=0,0,0,255
StringStyle=Bold
StringAlign=Left
Text="%1"
InlineSetting=Color | 0,0,0,0
InlinePattern="_"
In your real skin, you'd add the Substitute option to whatever measure your string is coming from. You can use whatever symbol you want, I used an underscore just for simplicity. In the MeterTest meter, the code is simply printing the underscores in a transparent color. You can get text that looks like "BlahBlah ..." instead of "BlahBlah...", so it's not perfect.
Gadgets Wiki GitHub More Gadgets...
Frasier
Posts: 7
Joined: August 10th, 2012, 3:38 pm

Re: String Meter "ClipString" not working correctly

Post by Frasier »

It happens with all kinds of combinations of font, font size, meter width, etc. It's just a matter of the text - in each meter configuration, you can easily find some texts that are clipped incorrectly. Something is broken here, maybe it's the fault of DirectX, but nevertheless this should be fixed somehow, because it often produces ugly results...

Your work-around is very creative, but unfortunately, it will also mask out the replacement char if it actually is part of the original text. Of course, this can also be fixed by working around it, but this gets way too complicated just for clipping correctly...

Regards!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4885
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: String Meter "ClipString" not working correctly

Post by eclectic-tech »

Frasier wrote: October 21st, 2022, 5:45 pm It happens with all kinds of combinations of font, font size, meter width, etc. It's just a matter of the text - in each meter configuration, you can easily find some texts that are clipped incorrectly. Something is broken here, maybe it's the fault of DirectX, but nevertheless this should be fixed somehow, because it often produces ugly results...

Your work-around is very creative, but unfortunately, it will also mask out the replacement char if it actually is part of the original text. Of course, this can also be fixed by working around it, but this gets way too complicated just for clipping correctly...

Regards!
I agree that the results can be ugly when relying on ClipString=1 or ClipString=2 to determine what is display4ed in a string meter based on the meter width and text content, but I also don't believe this can be 'fixed' easily. **

SilverAzide offered a novel solution, but I think the best solution is to use a simple Container meter to control the length of text that is displayed in your string meter.
Varying the width of the container meter will clip the text at exactly the width you determine regardless of the text content.

Here is some code that shows similar string meters. The top string uses ClipString=1, the second and third rows use ClipString=2 and ClipStringW=#Width#, while the fourth row uses a container meter.

Code: Select all

; ========= Metadata ==========
[Metadata]
Name=
Author=
Information=
; BY=attribution / SA=share-alike / ND=no-derivatives / NC=non-commercial
License=CC BY-SA-NC 3.0
Version=

; ========= Variables ==========
[Variables]
Width=150

; ========= Skin Settings ==========
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
Group=#RootConfig#
BackgroundMode=2
SolidColor=0,0,0,100

; ========= Measures ==========



; ========= Meter Styles ==========



; ========= Meters ==========
[MeterString]
Meter=STRING
X=10
Y=10
W=(#Width#-10)
H=14
ClipString=1
FontFace=Segoe UI
FontColor=220,220,220
FontSize=10
StringStyle=BOLD
StringAlign=LEFT
Text=Using 'ClipString=1' you get: D: New Order: 1x CarWashWax - Fillversion1234
DynamicVariables=1

[MeterString2]
Meter=STRING
X=r
Y=10R
ClipString=2
ClipStringW=(#Width#-10)
ClipStringH=14
FontFace=Segoe UI
FontColor=220,220,220
FontSize=10
StringStyle=BOLD
StringAlign=LEFT
Text=Using 'ClipString=2', #*Width*#, and 'H=14' you get: D: New Order: 1x CarWashWax - Fill Version12345 | And So On
DynamicVariables=1

[MeterString3]
Meter=STRING
X=r
Y=10R
H=14
ClipString=2
ClipStringW=(#Width#-10)
FontFace=Segoe UI
FontColor=220,220,220
FontSize=10
StringStyle=BOLD
StringAlign=LEFT
Text=0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
DynamicVariables=1

[MeterContainer]
Meter=Shape
X=10
Y=80
Shape=Rectangle 0,0,(#Width#-10),15 | StrokeWidth 1
DynamicVariables=1

[MeterContainedString2]
Meter=STRING
H=14
FontFace=Segoe UI
FontColor=220,220,220
FontSize=10
StringStyle=BOLD
StringAlign=LEFT
Text=Using a 'Container' you get: "D: New Order: 1x CarWashWax - Fill Version12345 | And So On | And So On | And So On
DynamicVariables=1
Container=MeterContainer

[MeterBar]
Meter=Image
X=10
Y=10R
SolidColor=255,25,25
W=[#Width]
H=14
DynamicVariables=1
MouseScrollUpAction=[!SetVariable Width (Clamp(#Width#+11,150,840))][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable Width (Clamp(#Width#-11,150,840))][!UpdateMeter *][!Redraw]
Tooltiptext=Scroll to Change Width | Current: #Width#

Scroll the red line meter to change the width and watch the actions of the 2 ClipString string versus the container method. I think you can have better control by using the Container meter method.

{Click image below to show animation}
clipping.gif
** The DevTeam may have other ideas on possible solutions'...
You do not have the required permissions to view the files attached to this post.
User avatar
Brian
Developer
Posts: 2536
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: String Meter "ClipString" not working correctly

Post by Brian »

Frasier wrote: October 21st, 2022, 5:45 pm It happens with all kinds of combinations of font, font size, meter width, etc. It's just a matter of the text - in each meter configuration, you can easily find some texts that are clipped incorrectly.
Could you point to other instances of this, because I can't recall this ever being reported before this.

Regardless...

SilverAzide is correct on this, D2D (specifically DirectWrite) controls all the logic in regards to "trimming" text. There are a couple of options they provide, but none of the options are related to this particular issue.

I do believe this is a bug with DirectWrite, and it seems to be related to the "Bold" calculations either provided by the font itself, or in how DirectWrite increases the "size" of its layout box based on the bold setting. The same issue happens with FontFace=Segoe UI Bold and InlineSetting=Weight | xxx (where "xxx" is greater than 649, or anything above SemiBold).

You can try the above solutions, or just remove StringStyle=Bold, but you may want "some" boldness (like SemiBold) to the font (and I would use AntiAlias as well). Something like this:

Code: Select all

[Meter]
Meter=STRING
X=10
Y=10r
W=190
H=14
ClipString=1
FontFace=Segoe UI SemiBold
FontColor=220,220,220
FontSize=10
StringAlign=LEFT
Text=D: New Order: 1x CarWashWax - Fillversion12345
AntiAlias=1
Probably not the answer you wanted...

-Brian
Frasier
Posts: 7
Joined: August 10th, 2012, 3:38 pm

Re: String Meter "ClipString" not working correctly

Post by Frasier »

Thanks for all your answers and suggestions! I know it's possible to use a container for pixel-perfect clipping, but this lacks the visual indicator that clipping occurred, which is very useful. It's a pity that the bug is in the OS itself, so we can't fix it. Maybe this can be reported to MicroSoft somehow? It's not only occurring with bold fonts, btw. - I just checked "Caibri" regular and it also clips incorrectly...

Anyway, I'll try to check some more fonts to see if any of them looks good and clips correctly. If not, I'll need to go with the container solution, because the incorrect clipping often simply discards too much of the text for the remaining part to be useful.

Regards!

EDIT: currently, "Arial Rounded MT Bold" (StringStyle=NORMAL) looks very promising! Seems to be bold by itself and seems to clip correctly! Also "Segoe UI Black" seems to work, although this is really "heavy"... Just in case somebody else is also looking for a bold font with correct clipping. Maybe the info about clipping issues can be included in the manual? Maybe it helps others...

EDIT2: Sorry to report that "Arial Rounded MT Bold" also has serious clipping issues with some strings. Really strange - it used to work fine but after I restarted the computer, the clipping was incorrect again! How is that possible??? Will have to resort to clipping by container...