Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: JScript Panel (Read 319876 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: JScript Panel

Reply #875
Code: [Select]
var tmp = utils.CreateTextLayout("some long string", "font_name", font_size_px);
var height_px = tmp.CalcTextHeight(max_width);
tmp.Dispose()

If you wanted to use the full ITextLayout interface for scrolling* text, the docs with example are here....

https://marc2k3.github.io/jscript-panel/docs/namespaces/utils/#utilscreatetextlayouttext-font_name-font_size-font_size-font_style-font_stretch-text_aligment-paragraph_aligment-word_wrapping

* when I say scrolling, I mean with the mouse wheel. I've been far too lazy to write any scrollbar or even pinch the ones from the smooth/jsplaylist scripts.

Re: JScript Panel

Reply #876
I confused myself.
I search a EstimateLineWrap replacement.
Code: [Select]
var gp = tmp_img.GetGraphics();
ctab[i].total_lines = gp.EstimateLineWrap(ctab[i].text, g_font, ww - (H_PADDING * 2) - padx).toArray().length;

Do it is possible to scroll to a specific line in TextLayout?

Re: JScript Panel

Reply #877
No, you can't get the text split in to an array of lines. I thought you only wanted the height of the overall text which is what you came to me about when I nuked the old DrawString methods ages ago. You had to multiply the number of lines by the height of each line. The new method just gives the overall height in pixels.

As for scrolling, you can adjust the vertical offset. That's what the example included in link is all about. You might have to resize the panel so it's quite small so you can see the effect.

Re: JScript Panel

Reply #878
I have modified all my script for V3.
Only Lyrics remained a small detail.
I' missing a EstimateLineWrap replacement.
I patch with a fixed heigth but not is but it's not so precise.
Your EstimateLineWrap V1 is exportable as function?
Or a via to get it?

Re: JScript Panel

Reply #879
It's precise enough for me.



Here's my C++ if you or anyone else wants to rip it apart/tell me what I'm doing wrong.

Code: [Select]
STDMETHODIMP Utils::CreateTextLayout(BSTR text, BSTR font_name, float font_size, UINT32 font_weight, UINT32 font_style, UINT32 font_stretch, UINT32 text_alignment, UINT32 paragraph_alignment, UINT32 word_wrapping, ITextLayout** out)
{
RETURN_HR_IF_NULL(E_POINTER, out);

const std::wstring name_checked = FontHelper::get().get_name_checked(font_name);
wil::com_ptr_t<IDWriteTextFormat> text_format;
wil::com_ptr_t<IDWriteTextLayout> text_layout;

RETURN_IF_FAILED(g_dwrite_factory->CreateTextFormat(name_checked.data(), nullptr, static_cast<DWRITE_FONT_WEIGHT>(font_weight), static_cast<DWRITE_FONT_STYLE>(font_style), static_cast<DWRITE_FONT_STRETCH>(font_stretch), font_size, L"", &text_format));
RETURN_IF_FAILED(g_dwrite_factory->CreateTextLayout(text, SysStringLen(text), text_format.get(), 512.f, FLT_MAX, &text_layout));
RETURN_IF_FAILED(JSGraphics::apply_alignment(text_layout.get(), text_alignment, paragraph_alignment, word_wrapping));

*out = new ComObjectImpl<TextLayout>(text_layout);
return S_OK;
}

Code: [Select]
STDMETHODIMP TextLayout::CalcTextHeight(float max_width, float* out)
{
RETURN_HR_IF_NULL(E_POINTER, out);
RETURN_HR_IF(E_POINTER, !m_text_layout);

DWRITE_TEXT_METRICS metrics{};
RETURN_IF_FAILED(m_text_layout->SetMaxWidth(max_width));
RETURN_IF_FAILED(m_text_layout->GetMetrics(&metrics));
*out = metrics.height;
return S_OK;
}


Re: JScript Panel

Reply #880
My script follows another approach:

Code: [Select]
var layout = utils.CreateTextLayout("", 'Segoe UI', 24);

function on_paint(gr) {
gr.WriteTextLayout(layout, g_backcolour, 0, 0, ww, wh, 0);
// LINE_HEIGHT ??
gr.FillRectangle(0, Math.floor(posy), ww, (tab[i].total_lines*LINE_HEIGHT), g_ovbg_highlightcolour);
gr.WriteText(tab[i].text, g_font, text_colour, H_PADDING, Math.floor(posy)-1, ww-H_PADDING*2, (tab[i].total_lines*LINE_HEIGHT), g_txt_align, 2, 0, 0);
}

do it is possible to calculate tab.total_lines before gr.WriteText ?


Re: JScript Panel

Reply #882
Documentation have a mistake:
utils.CreateTextLayout(text, font_name, font_size[, font_size, font_style, font_stretch, text_aligment, paragraph_aligment, word_wrapping])
have to be:
utils.CreateTextLayout(text, font_name, font_size[, font_weight, font_style, font_stretch, text_aligment, paragraph_aligment, word_wrapping])


Re: JScript Panel

Reply #884
do it have a replacement for fb.GetNowPlaying().SetPlaycount(0) ?
or it is replaced by internal "Play count" ?


Re: JScript Panel

Reply #886
When use WriteTextLayout instead of WriteText?



Re: JScript Panel

Reply #889
That means you've exceeded his patience.
It's your privilege to disagree, but that doesn't make you right and me wrong.


Re: JScript Panel

Reply #891
Hi Marc, Thanks for this addon and all the sample scripts.  Been using SMP on 1.6, so I'm very glad to see this is working beautifully with 2.0.  The only component I looked for but didn't find is one that will display an artist's top tracks from Last.fm.  On SMP, the YouTube track manager one used to do this.  Any chance something like this is coming for JSP 3?

Thanks again for all your efforts and the time you spend answering all our dumb questions. :)


Re: JScript Panel

Reply #893
@always.beta  - I've added support for Gui Fx Transport to Smooth Playlist. Save both these files inside samples\smooth

https://raw.githubusercontent.com/marc2k3/jscript-panel/main/component/samples/smooth/common.js
https://raw.githubusercontent.com/marc2k3/jscript-panel/main/component/samples/smooth/jssp.js

Now right click the panel on the header bar/empty space/scrollbar and select panel properties. Change the value of SMOOTH.RATING.FONT to 1.

@hexenszene - you can save this updated file inside the component folder\samples\js

https://raw.githubusercontent.com/marc2k3/jscript-panel/main/component/samples/js/list.js

Top tracks and top tags have been added. I was going to add top albums but the results are utter garbage.



Re: JScript Panel

Reply #896
I'll probably change the option in the next component release to something more understandable like SMOOTH.RATING.FONT.GUIFX and make it true/false.

The current 0/1 option is a bit cryptic.

edit: changes made here

https://github.com/marc2k3/jscript-panel/commit/381945e0713a5f8811c5a7444d57741f4940e02c

I've compromised a bit with a font size of 16. 14 was too small for me.

Just the single file updated...

https://raw.githubusercontent.com/marc2k3/jscript-panel/main/component/samples/smooth/common.js

Re: JScript Panel

Reply #897
I've compromised a bit with a font size of 16. 14 was too small for me.
The hollow ⭐ icon of the FontAwesome font, paired with the 18th font, will make the list look like ⭐ is easier to capture people's eyeballs than the title, which is purely my personal opinion.
Thanks again.

Re: JScript Panel

Reply #898
I managed to break* last.fm charts with that last list.js update so I've just fixed that. Link remains the same,

*the text showed but not the bar charts which I completely missed.

This works brilliantly!  Thanks very much Marc!  Really appreciate it. :)

Re: JScript Panel

Reply #899
Hi Marc,
I'm trying to use the following script to spin disc art :
https://gist.githubusercontent.com/marc2k3/1d449cc5bbb2fcfdb51157e49d679ad6/raw/4db85978e8b414d2aa3f4d3280457f8b5943f611/spinny%2520album%2520art%2520nonsense.txt

I'm using JScript Panel version 2.8.8 and it gives me the following error :
"JScript Panel v2.8.8 (Spinny Album Art Nonsense by marc2003)
Erreur d’exécution JavaScript:
The object doesnt manage the property or method « CreateImage » (please bear in mind i had to translate it so it may not be the exact translation)
File: <main>
Line: 26, Col: 1"

Do i need to upgrade JScript panel ?

ps : using CUI (if that matters)
Thanks