TextStyle handling

• Jan 21, 2013 - 23:11

I have just been looking in libmscore/style.cpp at the problem where text elements for Title, Subtitle, Composer and Lyricist are not aligned correctly when reading a MuseScore file that contains <TextStyle> elements. Particularly a file from 1.2, although I think it also applies to 2.0 scores that have explicit TextStyles.

The problem is that the TextStyle structures are filled in with ONLY the data read from the file. The defaults that were initialized for each kind of TextStyle get completely discarded by the assignment in StyleData::setTextStyle(const TextStyle& ts), including the default offsets. That is why the text elements are all clustered around the top left corner of the heading box.

Now, I was going to try fixing this within TextStyleData::read(XmlReader& e), by filling in the new TextStyle instance with the defaults for the particular kind of TextStyle. But this is complicated a lot by a change in the XML format.

The 1.2 XML format uses <TextStyle name="name">, and in TextStyleData::read(), this name attribute is fetched using name = e.attribute("name");

This would then be a good point at which to fill in the defaults, before reading the child elements.

However, the 2.0 XML format doesn't use the name attribute. Instead, it uses a child tag <name>name</name>. It seems to me that this is very wrong, because we can't tell in what sequence the child tags will be read, and so may have to read other tags before we know what kind of TextStyle we are actually populating.

Can I propose changing back to using an attribute for the TextStyle's name instead of a child tag?

Cheers
Tony


Comments

In reply to by chen lung

It may be related, but I was investigating my own experience of loading my jazz lead sheets from 1.2 into the current 2.0 builds.

The main point of my report above is to highlight the XML problem that is impeding a clean solution. I'm not an XML expert, but it seems to me that child tags should only be used for non-identifying properties of an element, and that the identifying property (in this case the name) should properly be an attribute of the element, as it is in 1.2.

In reply to by TonyM-softins

I think that maybe there are changes to the whole XML structure in 2.0. Style names are used as data for a drop-down box in 2.0, which is presumably why Werner has used a child tag for them. There must be another id tag for the style in 2.0. What we could do with is for Werner to publish his XML DTDs so we can fully understand how his structures work - I'm also having a few issues with the instruments.xml file I am working on, as I have had no access to the DTD for that.

In reply to by ChurchOrganist

The list of valid text style names is set up in the function initStyle(). It is this list that would be used to populate a drop-down, not the content of an XML file. When reading XML and encountering a TextStyle tag, we really need to know which of those text styles we are about to create before reading through the child elements. That is why the TextStyle tag itself needs an attribute telling us which of the built-in text styles to use (as it did in 1.2).

I'm still rather new to the MuseScore community. Does Werner read the discussions in this forum? I have had a quick look around and haven't seen his name on any posts. How do technology decisions such as this get discussed and agreed upon?

I'm also not yet clear when it is appropriate to do each of the following, regarding 2.0 development:

  1. Post to this forum
  2. Post to the Issue Tracker
  3. Post to the musescore-dev mailing list

Guidance on this would be most welcome!

The text style should be completly initialized by a read (starting with an empty style). The style name is only a tag. Especially there is should be no need to initialize the style with a build-in style. Unstyled text elements save a text style which has no name.
The wrong text position is probably the result of a semantic change of the style properties in 2.0.

In reply to by [DELETED] 3

One of my goals with this is to load correctly scores that were created in 1.2 (I think this is very important), and that use TextStyles (such as Jazz Lead Sheet). The TextStyle elements in a 1.2 file do not have the full set of child elements that are defined in 2.0, so we either need to define and perform a complete mapping from the 1.2 elements to the 2.0, or else allow missing child tags to assume a default value on loading (which is the point of my original post here).

In this particular case, the percentage Relative Offset values, which default in the built-in styles to (50,0) for Title and Subtitle, (0,100) for Lyricist/Poet and (100,0) for Composer, are not being set correctly when reading in the TextStyle from XML, but left as (0,0) for all of them. This is why those text items are clustered around the top left corner of the parent box.

In reply to by TonyM-softins

Correct import of 1.2 is indeed important. The right way to go is to expand read114.cpp. Best would be to expand this to a mostly independent version 1.2 importer module to get rid of the various special cases in the 2.0 read functions.

Maybe an easy solution is to initialize the TextStyle if a name tag is found. 1.2 files have a style name tag so there should be no need for another format change.

In reply to by [DELETED] 3

Thanks for the pointer to read114.cpp! I have just looked at it and discovered the reason for the misplaced title text.

Comparing the 1.2 and 2.0 XML text styles, I noticed that the 1.2 XML contained the same rxoffset and ryoffset tags that are used in 2.0 text styles, but they were not being acted upon.

In this code in read114.cpp, which you commited in July last year (according to "git blame"):

else if (tag == "TextStyle") {
TextStyle s;
s.read(e);
// settings for _reloff::x and _reloff::y in old formats
// is now included in style; setting them to 0 fixes most
// cases of backward compatibility
s.setRxoff(0);
s.setRyoff(0);
_style.setTextStyle(s);
}

the problem is the discarding of the relative offsets in the lines I have marked. I commented out those two lines and now title text from a 1.2 score is displayed correctly in 2.0. I haven't checked for other text styles, but rxoffset and ryoffset appear to be expressed as a percentage in both 1.2 and 2.0 files, so I don't understand the comment in the code above.

Do you still have an unanswered question? Please log in first to post your question.