瀏覽代碼

Smalls fixes

 - Fixing baseline difference between SDF and non SDF Font Map
 - Text2D now expose fontSuperSample and fontSignedDistanceField properties to compute separated Rendering Models
nockawa 8 年之前
父節點
當前提交
bacf088a6f
共有 2 個文件被更改,包括 28 次插入1 次删除
  1. 20 0
      canvas2D/src/Engine/babylon.text2d.ts
  2. 8 1
      src/Materials/Textures/babylon.fontTexture.ts

+ 20 - 0
canvas2D/src/Engine/babylon.text2d.ts

@@ -145,6 +145,8 @@
         public static defaultFontColorProperty: Prim2DPropInfo;
         public static textProperty: Prim2DPropInfo;
         public static sizeProperty: Prim2DPropInfo;
+        public static fontSuperSampleProperty: Prim2DPropInfo;
+        public static fontSignedDistanceFieldProperty: Prim2DPropInfo;
 
         @modelLevelProperty(RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 1, pi => Text2D.fontProperty = pi, false, true)
         /**
@@ -212,6 +214,24 @@
             this._size = value;
         }
 
+        @modelLevelProperty(RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 5, pi => Text2D.fontSuperSampleProperty = pi, false, false)
+        /**
+         * Get/set the font name to use, using HTML CSS notation.
+         * Set is not supported right now.
+         */
+        public get fontSuperSample(): boolean {
+            return this._fontTexture && this._fontTexture.isSuperSampled;
+        }
+
+        @modelLevelProperty(RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 6, pi => Text2D.fontSuperSampleProperty = pi, false, false)
+        /**
+         * Get/set the font name to use, using HTML CSS notation.
+         * Set is not supported right now.
+         */
+        public get fontSignedDistanceField(): boolean {
+            return this._fontTexture && this._fontTexture.isSignedDistanceField;
+        }
+
         public get isSizeAuto(): boolean {
             return false;
         }

+ 8 - 1
src/Materials/Textures/babylon.fontTexture.ts

@@ -231,7 +231,7 @@
             // In sdf mode we render the character in an intermediate 2D context which scale the character this._sdfScale times (which is required to compute the sdf map accurately)
             if (this._signedDistanceField) {
                 this._sdfContext.clearRect(0, 0, this._sdfCanvas.width, this._sdfCanvas.height);
-                this._sdfContext.fillText(char, 0, -this._offset);
+                this._sdfContext.fillText(char, 0, 0);
                 let data = this._sdfContext.getImageData(0, 0, width*this._sdfScale, this._sdfCanvas.height);
 
                 let res = this._computeSDFChar(data);
@@ -244,6 +244,13 @@
             // Fill the CharInfo object
             info.topLeftUV = new Vector2(this._currentFreePosition.x / textureSize.width, this._currentFreePosition.y / textureSize.height);
             info.bottomRightUV = new Vector2((this._currentFreePosition.x + width) / textureSize.width, info.topLeftUV.y + ((this._lineHeightSuper + 2) / textureSize.height));
+
+            if (this._signedDistanceField) {
+                let off = 1/textureSize.width;
+                info.topLeftUV.addInPlace(new Vector2(off, off));
+                info.bottomRightUV.addInPlace(new Vector2(off, off));
+            }
+
             info.charWidth = this._superSample ? (width/2) : width;
 
             // Add the info structure