فهرست منبع

getRawFontSize

Royi Bernthal 8 سال پیش
والد
کامیت
8697149c9f
2فایلهای تغییر یافته به همراه28 افزوده شده و 2 حذف شده
  1. 2 2
      gui/src/controls/control.ts
  2. 26 0
      gui/src/controls/textBlock.ts

+ 2 - 2
gui/src/controls/control.ts

@@ -10,7 +10,7 @@ module BABYLON.GUI {
         public _currentMeasure = Measure.Empty();
         private _fontFamily = "Arial";
         private _fontStyle = "";
-        private _fontSize = new ValueAndUnit(18, ValueAndUnit.UNITMODE_PIXEL, false);
+        protected _fontSize = new ValueAndUnit(18, ValueAndUnit.UNITMODE_PIXEL, false);
         private _font: string;
         public _width = new ValueAndUnit(1, ValueAndUnit.UNITMODE_PERCENTAGE, false);
         public _height = new ValueAndUnit(1, ValueAndUnit.UNITMODE_PERCENTAGE, false);
@@ -864,7 +864,7 @@ module BABYLON.GUI {
             return false;
         }
 
-        private _prepareFont() {
+        protected _prepareFont() {
             if (!this._font && !this._fontSet) {
                 return;
             }

+ 26 - 0
gui/src/controls/textBlock.ts

@@ -126,6 +126,32 @@ module BABYLON.GUI {
             }
         }
 
+        public getRawFontSize(): object {
+            var ignoreAdaptiveScaling: boolean = this._fontSize.ignoreAdaptiveScaling;
+
+            this._fontSize.ignoreAdaptiveScaling = false;
+            
+            var maxLineWidth: number = 0;
+
+            var _lines = this.text.split("\n").forEach(_line => {
+                //can't get context here? if so, have 2 calculations in _additionalProcessing instead? one for with idealWidth and one without
+                var lineWidth: number = this._parseLine(_line, context).width;
+
+                if (lineWidth > maxLineWidth) maxLineWidth = lineWidth;
+            });
+
+            this._prepareFont();
+
+            this._fontSize.ignoreAdaptiveScaling = ignoreAdaptiveScaling;
+
+            this._prepareFont();
+
+            return {
+                width: maxLineWidth,
+                height: this._fontOffset.height * this._lines.length + 'px'
+            }
+        }
+
         protected _parseLine(line: string='', context: CanvasRenderingContext2D): object {
           return {text: line, width: context.measureText(line).width};
         }