Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. private int processHtml(String string, int x, int y, Font defaultFont, boolean draw) {
  2. attributeList.clear();
  3. index = 0;
  4. Document document = Jsoup.parse(string);
  5. String text = stripHtmlTags(string) + (string.endsWith(" ") ? " " : "");
  6. loopElements(text, document.select("body").first().children());
  7.  
  8. int startX = x;
  9. for (int i = 0; i < text.length(); i++) {
  10. int character = text.charAt(i);
  11. if(character > 255)
  12. character = 255;
  13. Font font = defaultFont;
  14. if (character == 32) {//Space
  15. x += font.glyphSpacings[character];
  16. continue;
  17. }
  18. Attribute attribute = attributeList.containsKey(i) ? attributeList.get(i) : new Attribute();
  19. if ((int) attribute.get(Attributes.IMAGE.getKey()) != -1) {
  20. if ((int) attribute.get(Attributes.IMAGE.getKey()) != i)
  21. continue;
  22.  
  23. int spriteId = Integer.parseInt((String) attribute.get(Attributes.SRC.getKey()));
  24. Sprite sprite = Client.spriteCache.lookup(spriteId);
  25.  
  26. int width = (int) attribute.get(Attributes.WIDTH.getKey());
  27. if (width == 0)
  28. width = sprite.myWidth;
  29.  
  30. int height = (int) attribute.get(Attributes.HEIGHT.getKey());
  31. if (height == 0)
  32. height = sprite.myHeight;
  33.  
  34. if(draw)
  35. drawSprite(sprite, attribute, x, y, width, height, font);
  36.  
  37. x += width;
  38. } else {
  39. if ((boolean) attribute.get(Attributes.BOLD.getKey()))
  40. font = Client.boldFont;
  41. if(draw)
  42. font.render("" + text.charAt(i), x, y,
  43. (boolean) attribute.get(Attributes.SHADOW.getKey()),
  44. (boolean) attribute.get(Attributes.STRIKE.getKey()),
  45. (boolean) attribute.get(Attributes.UNDERLINE.getKey()),
  46. (int) attribute.get(Attributes.COLOUR.getKey()),
  47. (int) Math.round((double) attribute.get(Attributes.OPACITY.getKey()) * 256));
  48. x += font.glyphSpacings[character];
  49. }
  50. }
  51.  
  52. return x - startX;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement