Yuncong Zhang
5 年前
当前提交
5d2c9dab
共有 10 个文件被更改,包括 562 次插入 和 23 次删除
-
19Runtime/painting/text_span.cs
-
18Runtime/ui/painting/canvas_impl.cs
-
37Runtime/ui/painting/txt/mesh_generator.cs
-
82Runtime/ui/txt/layout.cs
-
4Runtime/ui/txt/layout_utils.cs
-
6Tests/Editor/Paragraph.cs
-
113Runtime/ui/txt/emoji.cs
-
11Runtime/ui/txt/emoji.cs.meta
-
205Tests/Resources/Emoji.png
-
90Tests/Resources/Emoji.png.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Unity.UIWidgets.foundation; |
|||
using UnityEngine; |
|||
using UnityEngine.Windows; |
|||
|
|||
namespace Unity.UIWidgets.ui { |
|||
public class EmojiUtils { |
|||
|
|||
static Image _image; |
|||
|
|||
public static Image image { |
|||
get { |
|||
if (_image == null || _image.texture == null) { |
|||
try { |
|||
_image = new Image( |
|||
Resources.Load<Texture2D>("Emoji") |
|||
); |
|||
} |
|||
catch (Exception e) { |
|||
_image = null; |
|||
} |
|||
} |
|||
|
|||
return _image; |
|||
} |
|||
} |
|||
|
|||
public static readonly Dictionary<uint, int> emojiLookupTable = new Dictionary<uint, int> { |
|||
{0x1F60A, 0}, |
|||
{0x1F60B, 1}, |
|||
{0x1F60D, 2}, |
|||
{0x1F60E, 3}, |
|||
{0x1F600, 4}, |
|||
{0x1F601, 5}, |
|||
{0x1F602, 6}, |
|||
{0x1F603, 7}, |
|||
{0x1F604, 8}, |
|||
{0x1F605, 9}, |
|||
{0x1F606, 10}, |
|||
{0x1F61C, 11}, |
|||
{0x1F618, 12}, |
|||
{0x1F62D, 13}, |
|||
{0x1F60C, 14}, |
|||
{0x1F61E, 15}, |
|||
}; |
|||
|
|||
public const int rowCount = 4; |
|||
public const int colCount = 4; |
|||
|
|||
public static Rect getUVRect(uint code) { |
|||
bool exist = emojiLookupTable.TryGetValue(code, out int index); |
|||
if (exist) { |
|||
return Rect.fromLTWH( |
|||
(index % colCount) * (1.0f / colCount), |
|||
(rowCount - 1 - (index / colCount)) * (1.0f / rowCount), |
|||
1.0f / colCount, 1.0f / rowCount); |
|||
} |
|||
|
|||
Debug.LogWarning($"Unrecognized unicode for emoji {code:x}"); |
|||
return Rect.fromLTWH(0, 0, 0, 0); |
|||
} |
|||
|
|||
public static void encodeSurrogatePair(uint character, out char a, out char b) { |
|||
uint code; |
|||
D.assert(0x10000 <= character && character <= 0x10FFFF); |
|||
code = (character - 0x10000); |
|||
a = (char) (0xD800 | (code >> 10)); |
|||
b = (char) (0xDC00 | (code & 0x3FF)); |
|||
} |
|||
|
|||
public static uint decodeSurrogatePair(char a, char b) { |
|||
uint code; |
|||
D.assert(0xD800 <= a && a <= 0xDBFF); |
|||
D.assert(0xDC00 <= b && b <= 0xDFFF); |
|||
code = 0x10000; |
|||
code += (uint) ((a & 0x03FF) << 10); |
|||
code += (uint) (b & 0x03FF); |
|||
return code; |
|||
} |
|||
|
|||
public static bool isSurrogatePairStart(uint c) { |
|||
return 0xD800 <= c && c <= 0xDBFF; |
|||
} |
|||
|
|||
public static bool isSurrogatePairEnd(uint c) { |
|||
return 0xDC00 <= c && c <= 0xDFFF; |
|||
} |
|||
|
|||
public static List<string> splitBySurrogatePair(string text) { |
|||
int start = 0; |
|||
List<string> list = new List<string>(); |
|||
for (int i = 0; i < text.Length; i++) { |
|||
if (i < text.Length - 1 && isSurrogatePairStart(text[i]) && isSurrogatePairEnd(text[i + 1])) { |
|||
if (i > start) { |
|||
list.Add(text.Substring(start, i - start)); |
|||
} |
|||
|
|||
start = i + 2; |
|||
list.Add(text.Substring(i, 2)); |
|||
i++; |
|||
} |
|||
} |
|||
|
|||
if (start < text.Length) { |
|||
list.Add(text.Substring(start)); |
|||
} |
|||
|
|||
return list; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7b8684b4e16cc4bf0a63f2da388d2227 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7a63b2e6e2c2045edb6a0be310ef2472 |
|||
TextureImporter: |
|||
internalIDToNameTable: [] |
|||
externalObjects: {} |
|||
serializedVersion: 10 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 1 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
streamingMipmaps: 0 |
|||
streamingMipmapsPriority: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -100 |
|||
wrapU: -1 |
|||
wrapV: -1 |
|||
wrapW: -1 |
|||
nPOTScale: 1 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 0 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spritePixelsToUnits: 100 |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spriteGenerateFallbackPhysicsShape: 1 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 0 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 0 |
|||
textureShape: 1 |
|||
singleChannelComponent: 0 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
platformSettings: |
|||
- serializedVersion: 2 |
|||
buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
bones: [] |
|||
spriteID: |
|||
internalID: 0 |
|||
vertices: [] |
|||
indices: |
|||
edges: [] |
|||
weights: [] |
|||
secondaryTextures: [] |
|||
spritePackingTag: |
|||
pSDRemoveMatte: 0 |
|||
pSDShowRemoveMatteOption: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue