a Rich Text library for LÖVE

Showcase your libraries, tools and other projects that help your fellow love users.

Which license should richtext use?

Poll ended at Sat Oct 09, 2010 4:36 pm

Public Domain
4
22%
BSD
1
6%
MIT/X11
5
28%
LPCL
0
No votes
zlib
6
33%
LGPL
1
6%
Other (please specify in replies)
1
6%
 
Total votes: 18

User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Idea: RichText

Post by leiradel »

arquivista wrote:My humble opinion. Rich Text would be a nice addition indeed but I think basic html and basic css would bring more text benefits than rich text and nice way to include and present external info. And since Rich Text is still a proprietary system and HTML/CSS an open one I think LOVE that is a free-source/open systems adept should be more "oriented" to adopt another open system like HTML/CSS.
But to be honest first I would also love to see printf with justify option (probably hard to implement right?)
I too would prefer to use a subset of HTML to format the text though CSS would be a PITA to make right. Hell, even web browsers can't seem to make CSS work the same across all of them!

The problems regarding bold and italic text in HTML could be solved by passing these resources to rich.new:

Code: Select all

local htmlCode = '<html><body><b>This is bold, and <i>this is bold italic</i></b><p/><img src="/images/cool_image.png"/><p/><font face="coolFont" size="20">big text with a cool font!</font></body></html>'

local resources = {
  defaultFont = { -- this could be a default of the library so we don't need to pass it to rich.new
    normal = '/fonts/Vera.ttf',
    bold = '/fonts/VeraBd.ttf',
    italic = '/fonts/VeraIt.ttf',
    boldItalic = '/fonts/VeraBI.ttf'
  },
  coolFont = { normal = '/fonts/CoolFont.ttf' } -- don't need the bold and italic variations for this font
}

local rt = rich.new( htmlCode, resources )
rich.new would load the fonts with a default size of, say, 12 points unless the <font> tag overrides the default size. Images would also be loaded as they're found. Loaded resources would be cached for reuse if they appear multiple times inside the same HTML code.

Having said that, I'd be glad to have a rich text library available no matter what codification it uses to format the text, so thanks for your efforts Robin.

Cheers,

Andre
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Idea: RichText

Post by Robin »

arquivista wrote:And since Rich Text is still a proprietary system and HTML/CSS an open one I think LOVE that is a free-source/open systems adept should be more "oriented" to adopt another open system like HTML/CSS.
I'm afraid you misunderstood my use of Rich Text. It does not refer to RTF, but to the general idea of marking up text (possibly with images). As a matter of fact, I'm not using any standard in richtext.lua. It's just tags (currently surrounded by {}, but might change to []. I only used curly braces because I'd have to escape [ and ] in the patterns, and complexity is death to this kind of projects.

As to why I'm not using HTML/CSS for this (And I won't ever. If you like to use it in your game, implement it yourself :P), there are three main reasons:
  1. For most of the time, it's insanely overpowered. Especially because LÖVE and this lib are mainly made for small, prototyped games, it wouldn't be very wise to use HTML and CSS
  2. It's awkward for the lover. You have to have HTML and CSS, wrapped inside Lua and additionally a lot of extra tables with images, fonts and metadata because HTML and CSS don't map to LÖVE very well.
  3. It would be bitchin' hard for me to implement. Even if I accept the most bare-bones and strictly-conforming HTML and CSS only, I'd estimate that 90-95% of the library would consist of the HTML and CSS parsers.
arquivista wrote:But to be honest first I would also love to see printf with justify option (probably hard to implement right?)
Actually, it wouldn't be that bad. It would require an extra processing step after each line, but that's it.

Also, I just realized that you can't use \n if you use wrapping in the current release. The lib will misunderstand what's happening and probably screw everything up. :crazy:
Help us help you: attach a .love.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Idea: RichText

Post by vrld »

Robin wrote:
  1. For most of the time, it's insanely overpowered. Especially because LÖVE and this lib are mainly made for small, prototyped games, it wouldn't be very wise to use HTML and CSS
  2. It's awkward for the lover. You have to have HTML and CSS, wrapped inside Lua and additionally a lot of extra tables with images, fonts and metadata because HTML and CSS don't map to LÖVE very well.
  3. It would be bitchin' hard for me to implement. Even if I accept the most bare-bones and strictly-conforming HTML and CSS only, I'd estimate that 90-95% of the library would consist of the HTML and CSS parsers.
4. HTML is ugly and bloated.
It is such a horrible language, that people created metalanguages just to prevent writing HTML. HTML is (supposed to be) easy to read by computers, but not very well suited to be written by human beings.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: a Rich Text library for LÖVE

Post by Robin »

Poll! Please help me decide what license to use. :)
Help us help you: attach a .love.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: a Rich Text library for LÖVE

Post by leiradel »

Robin wrote:Poll! Please help me decide what license to use. :)
zlib/png or public domain!

EDIT: I've just seen the poll. FAIL for replying with my vote.
Last edited by leiradel on Fri Oct 08, 2010 5:39 pm, edited 1 time in total.
User avatar
arquivista
No longer with us
Posts: 266
Joined: Tue Jul 06, 2010 8:39 am
Location: Insert Geolocation tag here
Contact:

Re: Idea: RichText

Post by arquivista »

Robin wrote: I'm afraid you misunderstood my use of Rich Text.
Yes I did. You mislead me! ;)

After check your stuff and RFT markup i noticed you are more "faking" rich text or do a kind of markup that you are calling "rich text". I think probably the "confusion" goes away if call it something else.

About the html/css, ok could be problematic (different ways of presentation/wrong sizes, etc) use external parsers/libraries based in installed browsers in OS but do a very basic internal parser even without images support would be nice and for me better than use the "slash" methods style of Lua/LOVE/other languages. Do you remember Flash inclusion basic of HTML about version v6 of the program? It acepted only the basic markup but gave flash a new and good way to display external data.

I only insisted in the ideia of use html inside because it's handy use in the game the same basic html distributed as instructions in the game directory so people don't have to switch windows. Also for "coding" HTML is the most used text markup and well know by almost everybody.
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Idea: RichText

Post by leiradel »

Just playing devil's advocate...
Robin wrote:For most of the time, it's insanely overpowered. Especially because LÖVE and this lib are mainly made for small, prototyped games, it wouldn't be very wise to use HTML and CSS
Prototyped? I think LÖVE is almost well suited to commercial games, and hope it becomes a viable option soon! As for overpower, I think the only tags one would need are <b>, <i>, <font>, <img>, <br>, <p> and maybe <a> (if/when LÖVE implements a function to open an web browser with some URL.)
Robin wrote:It's awkward for the lover. You have to have HTML and CSS, wrapped inside Lua and additionally a lot of extra tables with images, fonts and metadata because HTML and CSS don't map to LÖVE very well.
Isn't it just how it works right now? From the latest release:

Code: Select all

rt = rich.new{"{black}Hello {green}world{red}, {smile} how are {{}you} doing? {big}I'm doing fine.", 200, black = {0, 0, 0}, green = {0, 255, 0}, big = love.graphics.newFont(20), red = {255, 0, 0}, smile = love.graphics.newImage('face-laugh.png')}
Robin wrote:It would be bitchin' hard for me to implement. Even if I accept the most bare-bones and strictly-conforming HTML and CSS only, I'd estimate that 90-95% of the library would consist of the HTML and CSS parsers.
Agreed, but there are ready to use XML parsers implemented in pure Lua at http://lua-users.org/wiki/LuaXml. If you use a subset of XHTML (no CSS) then the parser is ~80% done. The only work left is to validate if the tags and their attributes are correct.

Again, I'm not against a new syntax to enrich text though I like to follow wide-used standards.

Cheers,

Andre
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Idea: RichText

Post by Robin »

I understand your points, but I still won't be implementing it. Ever. If you want to make a fork that can parse HTML/XML/whatever yourself, be my guest. :)

Just one thing:
Doing this:

Code: Select all

rt = rich.new{"{black}Hello {green}world{red}, {smile} how are {{}you} doing? {big}I'm doing fine.", 200, black = {0, 0, 0}, green = {0, 255, 0}, big = love.graphics.newFont(20), red = {255, 0, 0}, smile = love.graphics.newImage('face-laugh.png')}
in HTML would need something like

Code: Select all

rt = rich.new{[[<font class="black">Hello </font><font class="green">world</font><font style="red">, <img src="smile" /> how are {you} doing? <font style="font-face: big">I'm doing fine.</font>]], 200, black = {0, 0, 0}, green = {0, 255, 0}, big = love.graphics.newFont(20), red = {255, 0, 0}, smile = love.graphics.newImage('face-laugh.png')}
at the very least. So, it will be bulkier. ;)
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: a Rich Text library for LÖVE

Post by kikito »

Nitpick: On html, it would have to be either the modern-css-oriented:

Code: Select all

<span class='red'>...</span
or the older, font-driven:

Code: Select all

<font color='red'>...</font>
My point is that <font class=...> doesn't work.

But I agree that it would be bulkier and I don't think it would be necessary.
When I write def I mean function.
User avatar
arquivista
No longer with us
Posts: 266
Joined: Tue Jul 06, 2010 8:39 am
Location: Insert Geolocation tag here
Contact:

Re: a Rich Text library for LÖVE

Post by arquivista »

kikito wrote: or the older, font-driven:

Code: Select all

<font color='red'>...</font>
NO! NEIN! NÃO! NIET! MAIS NON!
font color is "kaput" since HTML 4.01 Strict / XHTML 1.0 Strict! ;D
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------
Post Reply

Who is online

Users browsing this forum: No registered users and 73 guests