TextMetrics-min.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.util.TextMetrics = function() {
  7. var A;
  8. return {
  9. measure : function(B, C, D) {
  10. if (!A) {
  11. A = Ext.util.TextMetrics.Instance(B, D)
  12. }
  13. A.bind(B);
  14. A.setFixedWidth(D || "auto");
  15. return A.getSize(C)
  16. },
  17. createInstance : function(B, C) {
  18. return Ext.util.TextMetrics.Instance(B, C)
  19. }
  20. }
  21. }();
  22. Ext.util.TextMetrics.Instance = function(B, D) {
  23. var C = new Ext.Element(document.createElement("div"));
  24. document.body.appendChild(C.dom);
  25. C.position("absolute");
  26. C.setLeftTop(-1000, -1000);
  27. C.hide();
  28. if (D) {
  29. C.setWidth(D)
  30. }
  31. var A = {
  32. getSize : function(F) {
  33. C.update(F);
  34. var E = C.getSize();
  35. C.update("");
  36. return E
  37. },
  38. bind : function(E) {
  39. C.setStyle(Ext.fly(E).getStyles("font-size", "font-style",
  40. "font-weight", "font-family", "line-height"))
  41. },
  42. setFixedWidth : function(E) {
  43. C.setWidth(E)
  44. },
  45. getWidth : function(E) {
  46. C.dom.style.width = "auto";
  47. return this.getSize(E).width
  48. },
  49. getHeight : function(E) {
  50. return this.getSize(E).height
  51. }
  52. };
  53. A.bind(B);
  54. return A
  55. };
  56. Ext.Element.measureText = Ext.util.TextMetrics.measure;