Comments (7)
The library now handles ANSI escape sequences (which measure to zero) and multi-char codepoints (which measure to one). Going to close for want of specific issues which are not dealing with monospace fonts and their lack of support for emoji and non-western script.
from picnic.
I did some tests here and it mostly works quite well, but making it any better will be really hard. Problem is that not all characters are the same width, even in monospace fonts. This is especially common for CJK fonts but basically means you can never assume single characters will align across all of unicode. Note there is information on this width in the unicode spec which could help, but it's not part of standard Java or kotlin APIs.
Examples of text width; depending on your font, some, all, or none of each block should line up but not all monospace fonts are made equal (hoping github won't mess this up):
latin | mmmmm |
Half-kana | ネネネネネ |
Full-latin| mmmmm |
Full-kana | ネネネネネ |
Emoji | 😃😃😃😃😃 |
CJK | 北北北北北 |
I've made a PR for a fix that will measure all characters consistently, but this may make alignment worse for emojis which are generally closer to full width (although often not exactly and font-dependant) and we shouldn't rely on this given there are many full-width characters in BMP.
The better (but potentially horrible to implement) fix would be to use the native font and rendering APIs to measure the text. These are all platform specific (Windows, Android, iOS...) and would require consumers to specify the output font.
But even if you have a pixel size for text it's not clear how it should be aligned just using other characters. Unicode defines a whole bunch of space characters with different widths but support and size will again depend on the font. Probably best to accept this as a know limitation for now
Bonus: Just to make measuring even more impossible, emoji can be modified meaning up to 7 unicode characters can turn into a single glyph (depending on font and OS support).
from picnic.
Update: character width data is available in icu4j: https://unicode-org.github.io/icu-docs/apidoc/released/icu4j/com/ibm/icu/lang/UProperty.html#EAST_ASIAN_WIDTH. This won't fix any of the above issues with fonts but will be a good indication whether to measure a char as one or two "units".
from picnic.
from picnic.
Came here to report this in a kotlin script
from picnic.
Unfortunately even with proper measurement, emoji rarely conform to monospace properly so the border characters and subsequent columns will always be misaligned.
from picnic.
Yep, I went in there to fix it and can see you are already handling it correctly, but it's just the additional width of the those unicode characters.
from picnic.
Related Issues (20)
- Notice year wrong? HOT 1
- Remove 'data' modifier from public API HOT 1
- Support for table with external borders but no inner borders for top/bottom HOT 3
- Feature request: render an empty footer HOT 3
- 0.3.0 introduced an undocumented dependency on java8 - String. HOT 4
- Columns are messed up with unicode chars HOT 7
- Columns are messed up with ANSI color codes HOT 4
- Markdown links break the table HOT 2
- calling `renderText` from Java HOT 4
- support horizontal rule HOT 2
- Characters don't work on Windows HOT 6
- Support hyperlinks HOT 3
- How to use picnic in Java HOT 2
- Passing a PrintStream to renderText
- Release note extraction does not work
- Jar for 0.6.0 in maven central is missing the .class files HOT 2
- Legacy mode HOT 2
- Dependency Dashboard
- Will this work on iOS? HOT 1
- Feature request: CSV (or DSV) rendering HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from picnic.