求助!在github下载的一个代码运行问题。----自定义中文字体集功能
近期由于对中文字体加载的需求,在网上找寻到一个解决方案,认为可以解决目前的需求,资源地址 :https://github.com/guowenfh/font-carrier2,我下载了该资源的代码,并按照说明安装好后,运行测试时控制台出现 Uncaught Error: Module name "../lib/index" has not been loaded yet for context: _. Use require([]) 运行不成功后我又多次尝试,结果依然。我想定是我对require的机制不了解的缘故,再次搜索网络,没有找到更深入的说明,只好发此求助,求教大佬,我要怎样才能让这个代码运行起来呢?require.js 下载到位,node版本为v16.17.0 npm8.15.0 百度云盘
font-carrier2
https://pan.baidu.com/s/1Sd9Mrx8eVQDNN0_zVzBKMA
提取码:yxqz 一眼Node版本太高。好几年前的库,降级到node 10版本试试 https://www.codeleading.com/article/93431898566/
希望对你有帮助 https://github.com/purplebamboo/font-carrier
官方库已经有维护了 谢谢各位的热心解答{:1_893:},我很少做前端,对require第一次接触{:1_924:}。 本帖最后由 acspace 于 2022-8-30 10:10 编辑
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test</title>
<script src="jquery.min.js"></script>
</head>
<body>
<script src="require.js"></script>
<script>
var fontCarrier2 = require('../lib/index')
var options = {
id: 'font-4',
horizAdvX: 256,
vertAdvY: 256
}
var fontface = {
fontFamily: 'font-4',
fontWeight: '400',
fontStretch: 'normal',
unitsPerEm: 256,
ascent: 221,
descent: -61
}
var glyphMap = {
'纯': {
unicode: '纯',
glyphName: 'uni7EAF',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni32431'
},
'空': {
unicode: '空',
glyphName: 'uni7A7A',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni31354'
},
'白': {
unicode: '白',
glyphName: 'uni767D',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni30333'
},
' ': {
unicode: ' ',
glyphName: 'uni20',
d: '',
horizAdvX: 65,
vertAdvY: 256,
name: 'uni32'
},
'迷': {
unicode: '迷',
glyphName: 'uni8FF7',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni36855'
},
'你': {
unicode: '你',
glyphName: 'uni4F60',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni20320'
},
'简': {
unicode: '简',
glyphName: 'uni7B80',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni31616'
},
'硬': {
unicode: '硬',
glyphName: 'uni786C',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni30828'
},
'笔': {
unicode: '笔',
glyphName: 'uni7B14',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni31508'
},
'楷': {
unicode: '楷',
glyphName: 'uni6977',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni26999'
},
'书': {
unicode: '书',
glyphName: 'uni4E66',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni20070'
},
'字': {
unicode: '字',
glyphName: 'uni5B57',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni23383'
},
'体': {
unicode: '体',
glyphName: 'uni4F53',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni20307'
},
'测': {
unicode: '测',
glyphName: 'uni6D4B',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni27979'
},
'试': {
unicode: '试',
glyphName: 'uni8BD5',
d:
'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni35797'
},
'1': {
unicode: '1',
glyphName: 'uni31',
d: 'svg-data ...',
horizAdvX: 140,
vertAdvY: 256,
name: 'uni49'
},
',': {
unicode: ',',
glyphName: 'uniFF0C',
d: 'svg-data ...',
horizAdvX: 256,
vertAdvY: 256,
name: 'uni65292'
},
'2': {
unicode: '2',
glyphName: 'uni32',
d:
'svg-data ...',
horizAdvX: 140,
vertAdvY: 256,
name: 'uni50'
},
'3': {
unicode: '3',
glyphName: 'uni33',
d:
'svg-data ...',
horizAdvX: 140,
vertAdvY: 256,
name: 'uni51'
}
}
var font = fontCarrier2.create(options)
font.setFontface(fontface)
Object.keys(glyphMap).forEach(key => {
var tmplGlyph = new fontCarrier2.Glyph(glyphMap)
tmplGlyph.__viewbox = font.__viewbox
font.setGlyph(key, tmplGlyph)
})
font.output({
path: './test/font-4'
})
</script>
</body>
</html>
上面是我按传统加载脚本的方式。验证结果就是上面说的故障,以前没有使用过require,看readem半天也没有明白{:1_924:},各位大佬,能不能指正一下,这个该怎么写,然后我再去消化,拜谢各位了{:1_893:} @415891872 应该不是node 版本的问题,我降到10.x 再降到8.x,重启服务器后,故障依然,相信应该是require的加载方式。{:1_893:} require.js 引入的时候 第一个参数是个数组,第二个是个函数吧 有点记不住了。
页:
[1]