Text Object #1429

Closed
niedzielski opened this Issue Jan 8, 2017 · 16 comments

Comments

Projects
None yet
5 participants
@niedzielski

niedzielski commented Jan 8, 2017

This is a feature request to add a special object for text. Text should preview in the editor using the font typeface and size specified on the object. The serialization of a text object should include text, font, and size specified. An example use case would be in designing an inventory, journal, or other text heavy screen.

@IMMZ

This comment has been minimized.

Show comment
Hide comment
@IMMZ

IMMZ Jan 8, 2017

Contributor

I'm joining to request. I think this feature would be very useful! For another use case example - game menu when you should place some entries (New game, Exit, etc.) on the screen.

Contributor

IMMZ commented Jan 8, 2017

I'm joining to request. I think this feature would be very useful! For another use case example - game menu when you should place some entries (New game, Exit, etc.) on the screen.

@bjorn bjorn changed the title from New: Text Object to Text Object Jan 8, 2017

@bjorn bjorn added the feature label Jan 8, 2017

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jan 8, 2017

Owner

A duplicate of #193, though this one is more descriptive. I definitely agree Tiled needs this.

Owner

bjorn commented Jan 8, 2017

A duplicate of #193, though this one is more descriptive. I definitely agree Tiled needs this.

@bjorn bjorn added the bounty label Jan 14, 2017

@bjorn bjorn added this to the Tiled 1.0 milestone Jan 27, 2017

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jan 27, 2017

Owner

@niedzielski Thanks for posting a generous bounty! Of course that raises the priority for me, but I first want to finish what I had committed to already which is the addition of layer grouping. In addition I needed to spend time fixing bugs, especially new ones, that I had introduced in Tiled 0.18.

Owner

bjorn commented Jan 27, 2017

@niedzielski Thanks for posting a generous bounty! Of course that raises the priority for me, but I first want to finish what I had committed to already which is the addition of layer grouping. In addition I needed to spend time fixing bugs, especially new ones, that I had introduced in Tiled 0.18.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jan 27, 2017

Owner

Also requested on the forum.

Owner

bjorn commented Jan 27, 2017

Also requested on the forum.

@bjorn bjorn added this to TODO in Roadmap Feb 13, 2017

@bjorn bjorn moved this from Tiled 1.0 to Up next in Roadmap Feb 13, 2017

@bjorn bjorn moved this from Up next to In Progress in Roadmap Feb 13, 2017

@bjorn bjorn self-assigned this Feb 13, 2017

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Feb 13, 2017

Owner

I've started working on this on the wip/text-object branch.

Owner

bjorn commented Feb 13, 2017

I've started working on this on the wip/text-object branch.

@bjorn bjorn closed this in 33e048b Feb 14, 2017

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Feb 14, 2017

Owner

Initial support for text objects will be available in the upcoming snapshot build. Here's an impression of what you could do with it:

-sandbox tmx tiled_148

What is missing still, though only in the Properties view, is a way to change the vertical and horizontal alignment of the text. I will try to get to that next week. Also missing is a mode in which you could have the size of the object automatically adjust to its contents, which I may add depending on the feedback.

The XML, JSON and Lua formats have been adjusted, though all these changes are preliminary and subject to change until release.

So, please try it out and let me know what you think!

Owner

bjorn commented Feb 14, 2017

Initial support for text objects will be available in the upcoming snapshot build. Here's an impression of what you could do with it:

-sandbox tmx tiled_148

What is missing still, though only in the Properties view, is a way to change the vertical and horizontal alignment of the text. I will try to get to that next week. Also missing is a mode in which you could have the size of the object automatically adjust to its contents, which I may add depending on the feedback.

The XML, JSON and Lua formats have been adjusted, though all these changes are preliminary and subject to change until release.

So, please try it out and let me know what you think!

@niedzielski

This comment has been minimized.

Show comment
Hide comment
@niedzielski

niedzielski Feb 16, 2017

@bjorn, woohoo!! I'm really excited to try this out and will give it a spin this weekend! Thanks!

@bjorn, woohoo!! I'm really excited to try this out and will give it a spin this weekend! Thanks!

@Eiyeron

This comment has been minimized.

Show comment
Hide comment
@Eiyeron

Eiyeron Feb 16, 2017

Where it looks like a neat idea, I'm more worried about how different platforms render differently fonts and texts, which would be very probably deviating from what you see in Tiled. Tiled is supposed to be agnostic, right, but I don't know if all loaders will support this feature soon.

Eiyeron commented Feb 16, 2017

Where it looks like a neat idea, I'm more worried about how different platforms render differently fonts and texts, which would be very probably deviating from what you see in Tiled. Tiled is supposed to be agnostic, right, but I don't know if all loaders will support this feature soon.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Feb 16, 2017

Owner

@Eiyeron This is a valid concern and can already lead to problems. By default Tiled currently specifies "sans-serif" as the font family, but this will definitely map to different fonts depending on the system. Already did the default space allocated for "Hello World" on Windows not suffice on Linux, causing the label to only read "Hello", since the "World" part was wrapped and clipped.

When taking the map into a game engine for sure there may be even greater differences. However, the problem should be mostly solved by making sure the same font family is used. To that end, it would make sense to eventually define the list of font families (and the default) you're using somewhere, and then be able to select only from those for the text objects. This is also important for consistency.

As for the feature being supported by loaders, it's just the way it is that new features only slowly trickle into the dozens of available loaders as people run into it. I would like to improve that by having better tests maps and a kind of feature matrix, but that is a different issue.

Owner

bjorn commented Feb 16, 2017

@Eiyeron This is a valid concern and can already lead to problems. By default Tiled currently specifies "sans-serif" as the font family, but this will definitely map to different fonts depending on the system. Already did the default space allocated for "Hello World" on Windows not suffice on Linux, causing the label to only read "Hello", since the "World" part was wrapped and clipped.

When taking the map into a game engine for sure there may be even greater differences. However, the problem should be mostly solved by making sure the same font family is used. To that end, it would make sense to eventually define the list of font families (and the default) you're using somewhere, and then be able to select only from those for the text objects. This is also important for consistency.

As for the feature being supported by loaders, it's just the way it is that new features only slowly trickle into the dozens of available loaders as people run into it. I would like to improve that by having better tests maps and a kind of feature matrix, but that is a different issue.

@bjorn bjorn referenced this issue Feb 17, 2017

Closed

Comments #193

@NinjaFighter

This comment has been minimized.

Show comment
Hide comment
@NinjaFighter

NinjaFighter Feb 17, 2017

Maybe a drop-shadow effect or semi-transparent background color could be useful for annotations (especially for annotations) (?)

Maybe a drop-shadow effect or semi-transparent background color could be useful for annotations (especially for annotations) (?)

@niedzielski

This comment has been minimized.

Show comment
Hide comment
@niedzielski

niedzielski Feb 18, 2017

@bjorn, I just tried 3409e33. This looks really good!

screenshot from 2017-02-18 13-26-46

Here's the JSON output:

{
  "height": 55.8227009708577,
  "id": 48,
  "name": "",
  "rotation": 0,
  "text": {
    "fontfamily": "Untitled1",
    "text": "3d Glasses\n+0\/0\nUncovers hidden items",
    "wrap": true
  },
  "type": "",
  "visible": true,
  "width": 208.538930065176,
  "x": 9.24666978631474,
  "y": 102.641532169764
}

*I don't have all the kinks worked out on the TTF version of the font I used so the kerning is incorrect and the font name is bogus. This has nothing to do with Tiled!

In the interest of trying to close out this ticket, the only thing that seems to be missing is the font size in the serialized output (unless I just missed it!). I was also really hoping the units of the font size could be specified in pixels but that's optional since I didn't specify it in the original description. Lastly, I'm seeing forward slashes escaped in the JSON output which is unexpected but I can open a separate issue for that if you like.

@bjorn, I just tried 3409e33. This looks really good!

screenshot from 2017-02-18 13-26-46

Here's the JSON output:

{
  "height": 55.8227009708577,
  "id": 48,
  "name": "",
  "rotation": 0,
  "text": {
    "fontfamily": "Untitled1",
    "text": "3d Glasses\n+0\/0\nUncovers hidden items",
    "wrap": true
  },
  "type": "",
  "visible": true,
  "width": 208.538930065176,
  "x": 9.24666978631474,
  "y": 102.641532169764
}

*I don't have all the kinks worked out on the TTF version of the font I used so the kerning is incorrect and the font name is bogus. This has nothing to do with Tiled!

In the interest of trying to close out this ticket, the only thing that seems to be missing is the font size in the serialized output (unless I just missed it!). I was also really hoping the units of the font size could be specified in pixels but that's optional since I didn't specify it in the original description. Lastly, I'm seeing forward slashes escaped in the JSON output which is unexpected but I can open a separate issue for that if you like.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Feb 18, 2017

Owner

Font size is 16 px by default, in which case it is not written out. Maybe I should make it always output it instead? You can actually set the font size in pixels in the properties view.

Escaping forward slashes is not needed but still valid JSON, so any conforming JSON parser should be able to handle it. If it doesn't I think you should open an issue about your JSON parser.

Owner

bjorn commented Feb 18, 2017

Font size is 16 px by default, in which case it is not written out. Maybe I should make it always output it instead? You can actually set the font size in pixels in the properties view.

Escaping forward slashes is not needed but still valid JSON, so any conforming JSON parser should be able to handle it. If it doesn't I think you should open an issue about your JSON parser.

@niedzielski

This comment has been minimized.

Show comment
Hide comment
@niedzielski

niedzielski Feb 18, 2017

Escaping forward slashes is not needed but still valid JSON

@bjorn, thanks! You're right! I've opened an issue against my linter.

Font size is 16 px by default, in which case it is not written out.

Here's how I'm changing the font size:

screenshot from 2017-02-18 15-15-51

I am using a pixel font that has very precise sizing. This value does not appear to correspond to pixel units or differs from how GIMP understands pixel size in a .ttf. I'm on a high DPI screen so maybe that's causing unexpected differences? In Gimp it appears exactly four pixels tall when set to 4px.

Maybe I should make it always output it instead?

That would be excellent!

I also noticed that font size as saved to the .tmx file does not appear to be preserved when closing and reopening the app.

Escaping forward slashes is not needed but still valid JSON

@bjorn, thanks! You're right! I've opened an issue against my linter.

Font size is 16 px by default, in which case it is not written out.

Here's how I'm changing the font size:

screenshot from 2017-02-18 15-15-51

I am using a pixel font that has very precise sizing. This value does not appear to correspond to pixel units or differs from how GIMP understands pixel size in a .ttf. I'm on a high DPI screen so maybe that's causing unexpected differences? In Gimp it appears exactly four pixels tall when set to 4px.

Maybe I should make it always output it instead?

That would be excellent!

I also noticed that font size as saved to the .tmx file does not appear to be preserved when closing and reopening the app.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Feb 20, 2017

Owner

Here's how I'm changing the font size:

Whoops, I had totally forgotten about the font chooser dialog regarding the size of the font. If you expand the "Font" property, you can set the "Pixel Size" there directly (I replaced "Point Size" with "Pixel Size" there). I can't actually use point size since this would make the pixel size of the text dependent on the DPI of the screen, which doesn't match well with all the other sizes being in pixels. The saving problems almost certainly relate to using the font dialog with point sizes as well.

I'm not sure what I could do about the font dialog. QFontDialog does not have an option to use pixel instead of point sizes.

Another way to maybe implement this, is to set the font size in points, but hardcode a certain DPI (so internally, I would actually set the font size in pixels based on a DPI of 96 for example). But I rather like the ability to be pixel-specific, just like in GIMP.

I am using a pixel font that has very precise sizing. This value does not appear to correspond to pixel units or differs from how GIMP understands pixel size in a .ttf.

Please let me know if using the Pixel Size sub-property allows you to use your font correctly.

Owner

bjorn commented Feb 20, 2017

Here's how I'm changing the font size:

Whoops, I had totally forgotten about the font chooser dialog regarding the size of the font. If you expand the "Font" property, you can set the "Pixel Size" there directly (I replaced "Point Size" with "Pixel Size" there). I can't actually use point size since this would make the pixel size of the text dependent on the DPI of the screen, which doesn't match well with all the other sizes being in pixels. The saving problems almost certainly relate to using the font dialog with point sizes as well.

I'm not sure what I could do about the font dialog. QFontDialog does not have an option to use pixel instead of point sizes.

Another way to maybe implement this, is to set the font size in points, but hardcode a certain DPI (so internally, I would actually set the font size in pixels based on a DPI of 96 for example). But I rather like the ability to be pixel-specific, just like in GIMP.

I am using a pixel font that has very precise sizing. This value does not appear to correspond to pixel units or differs from how GIMP understands pixel size in a .ttf.

Please let me know if using the Pixel Size sub-property allows you to use your font correctly.

@niedzielski

This comment has been minimized.

Show comment
Hide comment
@niedzielski

niedzielski Feb 20, 2017

You're right! Saving works fine when I use font properties instead of the dialog.

Font size now appears in JSON output:

{
  "height": 19,
  "id": 48,
  "name": "",
  "rotation": 0,
  "text": {
    "fontfamily": "Untitled1",
    "pixelsize": 4,
    "text": "3d Glasses\n+0\/0\nItem uncovers hidden items",
    "wrap": true
  },
  "type": "",
  "visible": true,
  "width": 92.375,
  "x": 5.375,
  "y": 79.1534
}

The pixel font size appears to render text about pixel perfect and matches the results achieved in GIMP.

c6b3356 meets everything I was hoping would be accomplished in this ticket \o/ I think there will be lots of room for new text features and improvements for a while to come but I hope this ticket establishes a base to build upon and certainly unblocks my uses.

I think you have to claim bounty. I don't have a whole lot of experience with this Bountysource stuff so let me know if there are any problems and I'll get it sorted. Thanks again!

You're right! Saving works fine when I use font properties instead of the dialog.

Font size now appears in JSON output:

{
  "height": 19,
  "id": 48,
  "name": "",
  "rotation": 0,
  "text": {
    "fontfamily": "Untitled1",
    "pixelsize": 4,
    "text": "3d Glasses\n+0\/0\nItem uncovers hidden items",
    "wrap": true
  },
  "type": "",
  "visible": true,
  "width": 92.375,
  "x": 5.375,
  "y": 79.1534
}

The pixel font size appears to render text about pixel perfect and matches the results achieved in GIMP.

c6b3356 meets everything I was hoping would be accomplished in this ticket \o/ I think there will be lots of room for new text features and improvements for a while to come but I hope this ticket establishes a base to build upon and certainly unblocks my uses.

I think you have to claim bounty. I don't have a whole lot of experience with this Bountysource stuff so let me know if there are any problems and I'll get it sorted. Thanks again!

@obiot obiot referenced this issue in melonjs/melonJS Feb 21, 2017

Open

add support for Text Object (Tiled 1.0) #875

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Feb 21, 2017

Owner

c6b3356 meets everything I was hoping would be accomplished in this ticket \o/ I think there will be lots of room for new text features and improvements for a while to come but I hope this ticket establishes a base to build upon and certainly unblocks my uses.

That's great to hear! I've claimed the bounty now. :-)

Owner

bjorn commented Feb 21, 2017

c6b3356 meets everything I was hoping would be accomplished in this ticket \o/ I think there will be lots of room for new text features and improvements for a while to come but I hope this ticket establishes a base to build upon and certainly unblocks my uses.

That's great to hear! I've claimed the bounty now. :-)

bjorn added a commit that referenced this issue May 9, 2017

Enabled editing of text alignment for text objects
Additions mostly copied from Qt Designer sources. I think it would make
sense to support Qt::Alignment in the QtPropertyBrowser solution, but
that'd be a somewhat bigger project...

This was the last missing functionality for issue #1429, for now.

@bjorn bjorn moved this from In Progress to Recently Completed in Roadmap May 9, 2017

@bjorn bjorn removed this from Recently Completed in Roadmap Jun 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment