npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

font2svgcode

v1.0.1

Published

将字符以<svg><text></text></svg>的形式包裹起来,可以设置字体渐变色,字体对其方式等,可以解决dom-to-image-more等类库导出图片时用css等其他方式设置的字体渐变效果无法导出的问题。

Downloads

14

Readme

font2svgcode

props

props:{
	Width:{
		type:String,
		default:'' //默认空时取值window.innerWidth||document.documentElement.offsetWidth;rpx单位的数值;auto:字符串长度*字符串的fontSize;建议不填写
	},
	Height:{
		type:String,
		default:'' //默认空,取值字符串的FontSize;rpx单位的数值,建议不填写
	},
	TextString:{
		type:String,
		default:'' //需要被转换的文本
	},
	FontSize:{
		type:String,
		default:'14px' //默认字体大小14px
	},
	FontFamily:{
		type:String,
		default:'' //渲染的字体
	},
	FontWeight:{
		type:String,
		default:'' //100,200,400,700,normal,bold
	},
	FontStyle:{
		type:String,
		default:'' //取值为''或者是normal渲染的值是normal否则为oblique(斜体显示)
	},
	Align:{
		type:String,
		default:'left' //取值 left|center|right
	},
	LinearGradient:{
		type:String,
		default:'' //渐变色,第一个值方向只有left和top,颜色值支持16进制的RGB/RGBA,例如 'left,#f00,#000','left,#f00 20%,#000 80%','left,#000000AA 20%,#0000ff22 80%'
	},
	Color:{
		type:String,
		default:'' //当LinearGradient生效的时候字体颜色失效
	}

使用方式

全局引入的方式

	<script src="./font2svgcode.js"></script>
    <script type="text/javascript">
        var svgCodeInstance = new font2svgcode({TextString:'测试',Width:'auto',FontSize:'40px',});
        console.log(svgCodeInstance.toSvgCdoe());
        console.log(svgCodeInstance.toSvgBase64());
    </script>

npm 引入

 npm install font2svgcode

示例:

	let font2svgcode  = require('../dist/font2svgcode.min.js');
	let font2svgcodeInstance = new font2svgcode({TextString:'测试'});
	console.log(font2svgcodeInstance.toSvgCode());
	console.log(font2svgcodeInstance.toSvgBase64());

注意

font2svgcode并不是真正的将字体转为svg图标,而是转为<svg><text></text></svg>这种格式

uniapp版本font2svg