Plugin: staff text is created with no style

• Feb 21, 2010 - 12:26
S4 - Minor

When a staff text is created, it does not follow the staff text style. This can be seen in the notenames.js plugin supplied with 0.9.5.

This can be corrected in file sctext.cpp, function static_Text_call() by replacing

if (text)
return context->engine()->newVariant(context->thisObject(), qVariantFromValue(text));


if (text)
{ text->setTextStyle(TEXT_STYLE_STAFF);
return context->engine()->newVariant(context->thisObject(), qVariantFromValue(text));

An alternative could be to put the setTextStyle() call in function SCursor::putStaffText() of file sccursor.cpp; but seems to me less than optimal if formatting properties will be added to the script Text object (which is desirable): setting the text style at cursor level would overwrite any custom formatting.



Before calling putStaffText, the text is not really a staff text. I guess the Text object could be used later for other types of text.
So I would prefer applying the style in putStaffText, maybe with a boolean parameter "applyStyle" ?

I see your point.

Perhaps a flexible (enough?) solution could be either (or both?):

* add a second parameter to the Text() constructor, with the required style (possibly using the numeric values of the TEXT_STYLE enum in style.h); if absent, it could default to 23 (TEXT_STYLE_STAFF) for backward compatibility;

* add a method Text.setTextStyle(textStyleNum) with a numeric parameter as above.

So, once the the Cursor.putStaffText() method is called, the text would be already styled.



Well, I made an attempt of a proposal. Attached is an edited version of the sctext.cpp file which:

  1. sets the text's textStyle to TEXT_STYLE_STAFF upon text creation, as a default;
  2. adds a Text.textStyle property (r/w) to adjust the text style after creation, if the default is not suitable;
  3. adds a Text.xOffset and a Text.yOffset properties (r/w) for adjusting the most evident text style parameters (I needed them... ;-) ).

Each change to the original source code (from SVN a few hours ago) is marked by comments.



Attachment Size 1.88 KB

I added xOffset and yOffset in r2781.
I'm not a big fan of exposing the Text style "magic numbers" to the plugin framework.
Maybe we could use strings?

Something else, the prefered way to sahre changes in the code is patch. If you checkout the code with TortoiseSVN, you can create a patch with right click -> TortoiseSVN->Create Patch. Patch files are allowed on the forum and issue tracker.

Status (old) active closed

Thanks for the reply. I have closed the issue.

I understand your concern with "magic numbers"; OTOH strings are cumbersome to identify as return values. Probably the whole style part of plugins needs a global approach.

About patch: I suspected there was a preferred way and patch was of course a good candidate, but I saw no examples in other issues I looked at (probably I overlooked it!). Thanks for the hint.