2017-05-08 41 views
1

React VR支持utf-8吗?如何在反应vr中使用utf-8?

例子:

export default class vrhw extends React.Component { 
    render() { 
    return (
     <View> 
     <Pano source={asset('chess-world.jpg')}/> 
     <Text 
      style={{ 
      backgroundColor: '#777879', 
      fontSize: 0.8, 
      fontWeight: '400', 
      layoutOrigin: [0.5, 0.5], 
      paddingLeft: 0.2, 
      paddingRight: 0.2, 
      textAlign: 'center', 
      textAlignVertical: 'center', 
      transform: [{translate: [0, 0, -3]}], 
      }}> 
      黎跃春 
     </Text> 
     </View> 
    ); 
    } 
}; 

AppRegistry.registerComponent('vrhw',() => vrhw); 
+0

http://react-vr.org – liyuechun

+0

HTTP://bbs.react-vr。 org – liyuechun

+1

尝试一下,你会看到。 –

回答

0

默认情况下ReactVR只支持罗马和斯拉夫字母,其他任何类型的字符,你会在自定义字体加载。 幸运的是,在官方仓库中已经有预制字体,它们只是不作为npm包的一部分发布。您必须手动将here的字体复制到您的项目中(假设在/fonts下)。

对于日语来说这很简单,因为您只需要加载一种字体。只需使用OVRUI中的loadFont方法,将其指向您的字体文件,并在创建时将结果传递给您的VRInstance

// vr/client.js 
import {VRInstance} from 'react-vr-web'; 
import * as OVRUI from 'ovrui'; 

// Store the default font, we'll extend it with Japanese support. 
const font = OVRUI.loadFont(); 

function init(bundle, parent, options) { 
    OVRUI.loadFont('../fonts/japanese.fnt', '../fonts/japanese.png').then((fallbackFont) => { 
    OVRUI.addFontFallback(font, fallbackFont); 

    const vr = new VRInstance(bundle, 'VRTEST', parent, { 
     font: font, 
     ...options, 
    }); 

    vr.render = function() {}; 
    vr.start(); 
    }); 
} 

window.ReactVR = {init}; 

对于中文,您需要加载三个字符集。由于loadFont是anync,因此我们需要跟踪加载的字体数量,并且只有在它们准备就绪后才初始化VRInstance

// vr/client.js 
import {VRInstance} from 'react-vr-web'; 
import * as OVRUI from 'ovrui'; 

const fallbackFonts = [{ 
    fnt: '../fonts/cjk_0.fnt', 
    png: '../fonts/cjk_0_sdf.png' 
}, { 
    fnt: '../fonts/cjk_1.fnt', 
    png: '../fonts/cjk_1_sdf.png' 
}, { 
    fnt: '../fonts/cjk_2.fnt', 
    png: '../fonts/cjk_2_sdf.png' 
}]; 

const font = OVRUI.loadFont(); 

function init(bundle, parent, options) { 
    let count = 0; 

    fallbackFonts.forEach((fontPaths) => { 
    count += 1; 

    OVRUI.loadFont(fontPaths.fnt, fontPaths.png).then((fallbackFont) => { 
     OVRUI.addFontFallback(font, fallbackFont); 
     count -= 1; 

     if (count === 0) { 
     const vr = new VRInstance(bundle, 'VRTEST', parent, { 
      font: font, 
      ...options, 
     }); 

     vr.render = function() {}; 
     vr.start(); 
     } 
    }); 
    }); 
} 

window.ReactVR = {init}; 

资源使用: