It is currently October 14th, 2024, 9:26 pm

Working with Angle on a String Meter (redux)

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
ryanchuang
Posts: 30
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

Post by ryanchuang »

HI,sorry,been away awhile.

Thank you all.

@balala,
Yes,that's codes I am looking for. However,due to there is no feasible way to verticalize Chinese characters from weather.com directly with .lua so far,I may resort to current repetitive steps to make sure the effect I prefered.

@jsmorley,
The .lua way is not feasible as one Chinese character is deemed 2 bytes whereas one latin letter is 1 byte. I did try to replace "VERTICAL" to Chinese phrases I prefered under [MeasureString],nothing is shown up. Yet back to English phrases,it does work.

I think currently,this is the only way you suggested that has worked so far I supposed:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeterOne]
Meter=String
X=20
StringAlign=Center
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
Text=V#CRLF#E#CRLF#R#CRLF#T#CRLF#I#CRLF#C#CRLF#A#CRLF#L


@ikarus1969
Hi,ikarus,your way has same issue as jsmorley's .lua. I have replaced the long English texts to Chinese characters under [Measure_Text],nothing is shown up either. Yet back to English texts,it does work.
Last edited by ryanchuang on September 28th, 2019, 2:18 pm, edited 3 times in total.
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with Angle on a String Meter (redux)

Post by balala »

ryanchuang wrote: September 28th, 2019, 6:30 am @balala,
Yes,that's codes I am looking for. However,due to there no feasible way to verticalize Chinese characters from weather.com directly with .lua so far,I may resort to current repetitive steps to make sure the effect I prefered.
As you wish. However "translating" the returned strings is easy, as described. But I didn't try to rotate the letters.
User avatar
ryanchuang
Posts: 30
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

Post by ryanchuang »

balala wrote: September 28th, 2019, 6:38 am As you wish. However "translating" the returned strings is easy, as described. But I didn't try to rotate the letters.
That's because latin letters always being written/read from left to right in horizontal way,there is only few instances that each latin letter in the whole words would be rotate vertically,ex: commercial banner in the street,ect., Before computer era,most of Chinese/Korean/Japanese characters were being written/read from right to left in vertical or horizontal way;after which for convenience on digital publishing,Chinese/Korean/Japanese characters written from left to right in horizontal way is acceptable and became mainstream lately. Still,Poem or certain educational books still written/read from right to left vertically.

Indeed,it's a very unusual request that I personally hoping Rainmeter somehow would find a way to easily customize which obviously could not.
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with Angle on a String Meter (redux)

Post by balala »

ryanchuang wrote: September 28th, 2019, 3:52 pm That's because latin letters always being written/read from left to right in horizontal way,there is only few instances that each latin letter in the whole words would be rotate vertically,ex: commercial banner in the street,ect., Before computer era,most of Chinese/Korean/Japanese characters were being written/read from right to left in vertical or horizontal way;after which for convenience on digital publishing,Chinese/Korean/Japanese characters written from left to right in horizontal way is acceptable and became mainstream lately. Still,Poem or certain educational books still written/read from right to left vertically.
Yeah, probably you're right. Unfortunately I don't know too much about the far east.
User avatar
ryanchuang
Posts: 30
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

Post by ryanchuang »

Hi all,

I need someone to write a .lua for me,so if the one string has another string text behind it,it will add #CRLF# between them;but,if one string is only one/last one,it will not. It's possible?? Thanks in advance.

Ex. if string text is:123,then added #CRLF# among them,like 1#CRLF#2#CRLF#3;but string text is:1,then just 1,add nothing.
User avatar
jsmorley
Developer
Posts: 22856
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with Angle on a String Meter (redux)

Post by jsmorley »

ryanchuang wrote: October 6th, 2019, 1:50 pm Hi all,

I need someone to write a .lua for me,so if the one string has another string text behind it,it will add #CRLF# between them;but,if one string is only one/last one,it will not. It's possible?? Thanks in advance.

Ex. if string text is:123,then added #CRLF# among them,like 1#CRLF#2#CRLF#3;but string text is:1,then just 1,add nothing.
Something like this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[LuaHost]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[MeasureString]
Measure=String
String=123

[MeterOutput]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=[&LuaHost:AddCRLF('[&MeasureString]')]
Test.lua:

Code: Select all

function AddCRLF(stringArg)

	if stringArg == '' then
            return stringArg
	end
	
	newString=stringArg:gsub('(.)','%1\r\n')
	newString=newString:match('(.+)\r\n$')
	
	return newString

end
1.jpg


So we are using gsub to add a \r\n (#CRLF#) after each character. Then we use match to strip off any trailing \r\n characters.

Note that we don't want an empty string to fail the match and attempt to return nil to Rainmeter. A nil will cause the Inline Lua string to fail in Rainmeter. In Lua, nil means "doesn't exist" or "false", and does not mean "" or an empty string.

https://docs.rainmeter.net/manual/lua-scripting/inline-lua/
http://lua-users.org/wiki/StringLibraryTutorial
http://lua-users.org/wiki/PatternsTutorial

This will almost certainly not work with Chinese/Korean/Japanese multi-byte characters, since although ostensibly no "measuring" is being done, there is some "measuring" that is under the covers in those functions, and garbled characters will likely be returned. You really just can't manipulate multi-byte characters in Lua. No way around that... Even the simple . (one of any character) pattern is really "one of any character byte". It will see a single Chinese character as two characters.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with Angle on a String Meter (redux)

Post by balala »

My approach would be a little bit different: I'd not use a lua script to achieve this, just a proper substitution on a String measure.
For instance if we remove the [LuaHost] measure from jsmorley's previous post and add two proper options to the [MeasureString] measure, we get the same result:

Code: Select all

[MeasureString]
Measure=String
String=123
RegExpSubstitute=1
Substitute="(.)":"\1#CRLF#"
Note that even if this procedure adds a final #CRLF# character after the whole string, this is ignored by Rainmeter.
This way you can avoid a lua script.
User avatar
jsmorley
Developer
Posts: 22856
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with Angle on a String Meter (redux)

Post by jsmorley »

balala wrote: October 6th, 2019, 3:20 pm My approach would be a little bit different: I'd not use a lua script to achieve this, just a proper substitution on a String measure.
For instance if we remove the [LuaHost] measure from jsmorley's previous post and add two proper options to the [MeasureString] measure, we get the same result:

Code: Select all

[MeasureString]
Measure=String
String=123
RegExpSubstitute=1
Substitute="(.)":"\1#CRLF#"
Note that even if this procedure adds a final #CRLF# character after the whole string, this is ignored by Rainmeter.
This way you can avoid a lua script.
And I think you can avoid the trailing #CRLF# anyway...

Code: Select all

[MeasureString]
Measure=String
String=中国語
RegExpSubstitute=1
Substitute="(.)":"\1#CRLF#","#CRLF#$":""

1.jpg


I only provided the Lua since that was what was asked for. I would likely use the RegExpSubstitute as well, unless there was some other manipulation or action in Lua that was required at the same time. Native Rainmeter is perfectly fine with multi-byte character sets.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16658
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with Angle on a String Meter (redux)

Post by balala »

jsmorley wrote: October 6th, 2019, 3:23 pm And I think you can avoid the trailing #CRLF# anyway...
Right. However, as I said, I think it's not needed.
jsmorley wrote: October 6th, 2019, 3:23 pm I only provided the Lua since that was what was asked for. I would likely use the RegExpSubstitute as well, unless there was some other manipulation or action in Lua that was required at the same time. Native Rainmeter is perfectly fine with multi-byte character sets.
Right again. However when I read ryanchuang's request, I immediately thought that a lua script is not needed, to achieved what he wants. He has to decide which solution does he prefere. Obviously if other string manipulations are required as well, it's a completely different discussion.
User avatar
ryanchuang
Posts: 30
Joined: September 13th, 2019, 4:23 am

Re: Working with Angle on a String Meter (redux)

Post by ryanchuang »

Sorry,late again.

Thank you for providing the solutions. This trick works:

Code: Select all

RegExpSubstitute=1
Substitute="(.)":"\1#CRLF#"
However,I have encountered one dilemma that I defined the dot(.) to one Chinese character in returning strings from Pressure and Visibility which have numerics with dot: 998.99 mb and 16.6 km. If I have implemented above substitution trick,Rainmeter will return/show all numerics with dot(.) in the Chinese character that I have assigned with which incorrect.

Ex,I have assigned the (.) to one Chinese character (點),so after I have added substitution trick in Pressure and Visibility strings,Rainmeter will returned with
點點點點點點 mb,instead of 998點99 mb or 點點點點 km,instead of 16點6 km

What does (.) mean in substitute ?? It's possible that replace it with another one that lest confuse in returning strings from Weather.com,such as Pressure and Visibility ?? Thanks in advance.

Note:if the returning strings has no dot(.),such as Humidity or Chance for precip,the substitution trick works fine.


Sorry,I figured out,just deleted one of #CRLF# in Text= that I have assigned. Thanks a lot,jsmorley and balala. :thumbup: