question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

word break cause by color tag

See original GitHub issue

Issue details

the second draw of font should not break the word “international”. It just one word with different color.

Reproduction steps/code

	public void render(float delta) {
		Gdx.gl.glClearColor(0.6f, 0.6f, 0.6f, 1.0f);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		
		batch.setProjectionMatrix(camera.combined);

		shape.begin(ShapeRenderer.ShapeType.Line);
		shape.setColor(Color.RED);
		shape.rect(0, VIRTUAL_HEIGHT - 600, 300, 600);
		shape.end();

		batch.begin();
		font.getData().setScale(0.5f);
		font.draw(batch, "[BLUE]Is this a bug? international string123456789abcdefghiklmn",
				0.0f, VIRTUAL_HEIGHT,
				300.f, Align.left, true);
              // [output](http://pasteboard.co/OPDave7xa.png)
		font.draw(batch, "[BLUE]Is this a bug? inter[RED]national string123456789abcdefghiklmn",
				0.0f, VIRTUAL_HEIGHT - 200,
				300.f, Align.left, true);
               // [output](http://pasteboard.co/OPuY5FCP6.png)
		batch.end();

	}


Version of LibGDX and/or relevant dependencies

libgdx 1.9.5

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
TCreutzenbergcommented, Jul 1, 2021

Nah, I spent so much time already, I’m not going to resign.

I already abandoned the option we talked about above as it turned out to be really crazy because recursive linebreaks are needed where you have to keep track of all runs which are already dangling behind the one to wrap, etc. Not really a sane option, I tried it so I know. Or I just didn’t get it working correctly, also possible.

Whenever something is overly complicated I often remember that in these cases normally the underlying data structure or architecture is not suited to the problem to be solved. After looking at the whole thing the problem with the data structure here is that wrapping is mixed with color changes. I.e. lines are broken because of color changes. That’s the reason why wrapping is so complicated. There is a really cool way to solve this problem I’m working on right now which would require the GlyphRuns to change the color-change handling a little bit, the rest of the code would even be simplified a lot and still using the all the methods which are already in use. It’ll basically will be only one GlyphRun per line. If GlyphRun color handling is not to be touched this can also changed to create GlyphRuns as they are now with a little overhead.

When I’m finished, please test with your project if you notice any difference. Even if you guys do not like it I will still use it for my own project, as I’ll be using color-markup in many texts I guess.

2reactions
NathanSweetcommented, Jun 27, 2021

I’m not on it. Best of luck! thar be dragonz

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrapping and breaking text - CSS: Cascading Style Sheets
An alternative property to try is word-break . This property will break the word at the point it overflows. It will cause a...
Read more >
Deep Dive into Text Wrapping and Word Breaking
A Break, Where Words Can't Break? For line breaks, you can use <br> inside of an element with white-space: nowrap or white-space: pre...
Read more >
word-break - CSS-Tricks
The word-break property in CSS can be used to change when line breaks ought to occur. Normally, line breaks in text can only...
Read more >
How do I wrap text in a pre tag? - html - Stack Overflow
word-wrap: break-word does not do what the question is asking for, it causes line wraps to happen even in between words. You can...
Read more >
How to Wrap Words in a <div> Tag with CSS - W3docs
Use the word-wrap property with the "break-word" value. div { white-space: pre-wrap; white-space: -moz-pre- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found