{"action":"created","issue":{"url":"https://api.github.com/repos/libgdx/libgdx/issues/3230","labels_url":"https://api.github.com/repos/libgdx/libgdx/issues/3230/labels{/name}","comments_url":"https://api.github.com/repos/libgdx/libgdx/issues/3230/comments","events_url":"https://api.github.com/repos/libgdx/libgdx/issues/3230/events","html_url":"https://github.com/libgdx/libgdx/issues/3230","id":90952118,"number":3230,"title":"GlyphLayout unexpected whitespace omitted","user":{"login":"scientistnm","id":933456,"avatar_url":"https://avatars.githubusercontent.com/u/933456?v=3","gravatar_id":"","url":"https://api.github.com/users/scientistnm","html_url":"https://github.com/scientistnm","followers_url":"https://api.github.com/users/scientistnm/followers","following_url":"https://api.github.com/users/scientistnm/following{/other_user}","gists_url":"https://api.github.com/users/scientistnm/gists{/gist_id}","starred_url":"https://api.github.com/users/scientistnm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scientistnm/subscriptions","organizations_url":"https://api.github.com/users/scientistnm/orgs","repos_url":"https://api.github.com/users/scientistnm/repos","events_url":"https://api.github.com/users/scientistnm/events{/privacy}","received_events_url":"https://api.github.com/users/scientistnm/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-25T12:41:13Z","updated_at":"2015-06-25T15:38:36Z","closed_at":"2015-06-25T14:45:08Z","body":"Hello,\r\n\r\nI will try to explain what I'm trying to do and what is the problem here.\r\nIf you don't consider this as a bug, then please explain how to overcome this behavior of GlyphLayout.\r\n\r\nI'm working on the 3D framework for TV platforms, than uses Libgdx underneath it.\r\nI'm trying to create 3D input field widget. It is basicallly a decal with texture that I've prepared in runtime while drawing BitmapFont into FBO.\r\n\r\nI noticed a problem that GlyphLayout omitts multiple whitespaces, and then my text isn't rendering correctly.\r\nAlso it omitts white spaces in the end and start of the run.\r\nThis is the problem for me because when I try to calculate position of the cursor in the input field...\r\nString that should be rendered and the count of Glyphs in GlyphLayout is not the same.\r\nSome of whitespaces are omitted during wrap, and those two are not in sync anymore.\r\n\r\nI sync the cursor index manually, RIGHT key (cursorIndex++), LEFT key (cursorIndex--).\r\nSo when I try to put cursor in the next line...the index of selected character in the string is not the same as the index of glyph in glyph layout...and I miss the correct position of where cursor should be.\r\n\r\nI have a workaround for it, but I'm not sure if this is the right way to do...\r\n\r\nIn the GlyphLayout class in wrap method, when I do this everything looks good in my usecase:\r\n\r\n// Determine index where first run ends, ignoring whitespace before the wrap index.\r\nint endIndex = wrapIndex;\r\n//for (; endIndex > 0; endIndex--)\r\n//\tif (!fontData.isWhitespace((char)first.glyphs.get(endIndex - 1).id)) break;\r\n\r\n// Determine index where second run starts, ignoring whitespace after the wrap index.\r\n     int startIndex = wrapIndex;\r\n//for (; startIndex < glyphCount; startIndex++)\r\n//if (!fontData.isWhitespace((char)first.glyphs.get(startIndex).id)) break;\r\n\r\nSo basically I prevented the white space omittment, and everything draws correct if I have multiple whitespaces together, also the number of characters in String and the number of glyphs in GlyphLayout is the same, and caluclation of cursor position is correct.\r\nIs the the right way to achieve this?\r\n\r\nIf this is the only way...I can send a pull request that changes the visibility of this method from private to protected, and I can override this behaviour.\r\n\r\nWhat do you think about this?\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/libgdx/libgdx/issues/comments/115297362","html_url":"https://github.com/libgdx/libgdx/issues/3230#issuecomment-115297362","issue_url":"https://api.github.com/repos/libgdx/libgdx/issues/3230","id":115297362,"user":{"login":"scientistnm","id":933456,"avatar_url":"https://avatars.githubusercontent.com/u/933456?v=3","gravatar_id":"","url":"https://api.github.com/users/scientistnm","html_url":"https://github.com/scientistnm","followers_url":"https://api.github.com/users/scientistnm/followers","following_url":"https://api.github.com/users/scientistnm/following{/other_user}","gists_url":"https://api.github.com/users/scientistnm/gists{/gist_id}","starred_url":"https://api.github.com/users/scientistnm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scientistnm/subscriptions","organizations_url":"https://api.github.com/users/scientistnm/orgs","repos_url":"https://api.github.com/users/scientistnm/repos","events_url":"https://api.github.com/users/scientistnm/events{/privacy}","received_events_url":"https://api.github.com/users/scientistnm/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T15:38:36Z","updated_at":"2015-06-25T15:38:36Z","body":"Ok, I understand that. Thats why I asked is there a way to make workaround that.\r\nI have looked in the TextArea.java and TextField.java...but having troubles understand what is really going on...it is lacking out of comments.\r\n\r\nBesides that, I noticed that when I type in my text field (I append new char to existing string, and ask bitmap font to draw it)...When the new line is wrapped on whitespace (new line is beginning with white space)...it will not draw the following multiple whitespaces.\r\nI think that this may be a side effect of omitting multiple whitespaces.\r\n\r\nIt would be nice if you can give me some instructions and advices how to achieve this.\r\nBasically I'm reinventing the wheel here, with the TextField.java but drawing it's content to texture and applying it to decal.\r\n \r\n"}}