mirror of
https://github.com/2234839/web-font.git
synced 2025-06-12 03:19:18 +08:00
改善前端页面
This commit is contained in:
parent
6f49a621d3
commit
a44f978ef5
1
.gitignore
vendored
1
.gitignore
vendored
@ -25,5 +25,6 @@ dist-ssr
|
||||
|
||||
llrt*
|
||||
font/*
|
||||
*.tar
|
||||
|
||||
dist_backend
|
@ -6,6 +6,7 @@ COPY dist/ /home/dist/
|
||||
EXPOSE 80
|
||||
CMD ["/home/llrt", "/home/app.lrt"]
|
||||
|
||||
# docker tag web-font:latest llej0/web-font:latest
|
||||
# docker tag llej0/web-font:latest llej0/web-font:latest
|
||||
# docker push llej0/web-font:latest
|
||||
# docker build -t llej0/web-font:latest .
|
||||
# docker build -t llej0/web-font:latest .
|
||||
# docker save -o llej0.web-font.latest.tar llej0/web-font:latest
|
57
README.md
57
README.md
@ -1,13 +1,13 @@
|
||||
# web font 字体裁剪工具
|
||||
|
||||
之前的版本请查看 master 分支,为了能使用 llrt ,我进行了重写,之后只维护此分支
|
||||
llrt超低的启动内存占用
|
||||

|
||||
|
||||
 llrt 超低的启动内存占用
|
||||
虽然 llrt 内存占用低,但它运行速度慢,只能到node的1/2。有运行速度要求的建议使用node/bun运行
|
||||
|
||||
## 起因
|
||||
|
||||
ui 需要展现一些特定的字体,但直接引入字体包又过大,于是想到了裁剪字体,一开始想的使用「字蛛」但他是针对静态网站的,而且实际他会多出许多英文的,估计是直接将源码中存在的文字都算进去了。
|
||||
后来又找到阿里的「webfont」 但他的字体有限,项目又不开源,所以自己写了这个
|
||||
ui 需要展现一些特定的字体,但直接引入字体包又过大,于是想到了裁剪字体,一开始想的使用「字蛛」但他是针对静态网站的,而且实际他会多出许多英文的,估计是直接将源码中存在的文字都算进去了。后来又找到阿里的「webfont」 但他的字体有限,项目又不开源,所以自己写了这个
|
||||
|
||||
## 在线尝试
|
||||
|
||||
@ -17,8 +17,7 @@ ui 需要展现一些特定的字体,但直接引入字体包又过大,于
|
||||
|
||||
1.裁剪字体包使其仅包含选中的字体
|
||||
|
||||
例如 如下图生成的字体包仅包含 「天地无极乾坤借法」
|
||||

|
||||
例如 如下图生成的字体包仅包含 「天地无极乾坤借法」 
|
||||
|
||||
<video src="./doc_img/功能演示.mkv" controls="controls" width:100% height:auto></video>
|
||||
|
||||
@ -32,14 +31,15 @@ ui 需要展现一些特定的字体,但直接引入字体包又过大,于
|
||||
|
||||
```css
|
||||
@font-face {
|
||||
font-family: "QIJIC";
|
||||
src: url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.eot"); /* IE9 */
|
||||
src: url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.eot?#iefix") format("embedded-opentype"), /* IE6-IE8 */
|
||||
url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.woff") format("woff"), /* chrome, firefox */
|
||||
url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.ttf") format("truetype"), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
|
||||
url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.svg#QIJIC") format("svg"); /* iOS 4.1- */
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-family: "QIJIC";
|
||||
src: url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.eot"); /* IE9 */
|
||||
src: url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.eot?#iefix") format("embedded-opentype"),
|
||||
/* IE6-IE8 */ url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.woff") format("woff"),
|
||||
/* chrome, firefox */ url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.ttf")
|
||||
format("truetype"), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
|
||||
url("http://127.0.0.1:3000/asset/font/1584680576469/令东齐伋复刻体.svg#QIJIC") format("svg"); /* iOS 4.1- */
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
}
|
||||
```
|
||||
|
||||
@ -53,34 +53,41 @@ ui 需要展现一些特定的字体,但直接引入字体包又过大,于
|
||||
|
||||
## 安装与使用
|
||||
|
||||
### 使用docker安装
|
||||
### 使用 docker 安装
|
||||
|
||||
https://hub.docker.com/repository/docker/llej0/web-font
|
||||
很小的包体积
|
||||

|
||||
https://hub.docker.com/repository/docker/llej0/web-font 很小的包体积 
|
||||
|
||||
docker compoose.yml
|
||||
|
||||
```yml
|
||||
version: 'latest'
|
||||
version: '3'
|
||||
services:
|
||||
app:
|
||||
image: llej0/web-font:latest
|
||||
image: docker.io/llej0/web-font:latest
|
||||
ports:
|
||||
- "8087:8087"
|
||||
volumes:
|
||||
- /home/zixu/code/webfont/font:/home/font
|
||||
- ./data:/home/font # 挂载本机字体目录
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 100M # 设置内存限制为100MB,根据实际需求来设置
|
||||
restart: on-failure # 设置重启策略为 on-failure
|
||||
|
||||
```
|
||||
其中font目录替换成你的字体文件存放目录
|
||||
|
||||
其中 font 目录替换成你的字体文件存放目录
|
||||
|
||||
### 使用node等运行时
|
||||
### 使用 node 等运行时
|
||||
|
||||
拉取项目,并将字体文件放到项目内的 font 目录下,然后运行:
|
||||
|
||||
pnpm install && pnpm build && pnpm build_backend && node ./dist_backend/
|
||||
|
||||
|
||||
|
||||
## 提供的服务
|
||||
|
||||
|
||||
|
||||
## 鸣谢
|
||||
|
||||
[字体天下](http://www.fonts.net.cn/commercial-free-32767/fonts-zh-1.html)
|
||||
|
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "webfont",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"version": "1.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"build_backend": "tsup && ./llrt2 compile ./dist_backend/app.cjs ./dist_backend/app.lrt",
|
||||
"docker": "docker build -t web-font:latest .",
|
||||
"docker_build": "docker build -t llej0/web-font:${npm_package_version} -t llej0/web-font:latest .",
|
||||
"docker_push": "docker push llej0/web-font:${npm_package_version} && docker push llej0/web-font:latest",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -21,4 +22,4 @@
|
||||
"vite": "^5.4.1",
|
||||
"vite-plugin-solid": "^2.10.2"
|
||||
}
|
||||
}
|
||||
}
|
28
src/App.css
28
src/App.css
@ -1,28 +0,0 @@
|
||||
@font-face {
|
||||
font-family: "CustomFont";
|
||||
src: url("/api.ttf?font=令东齐伋复刻体.ttf&text=令东齐伋复刻体问藏书房") format("truetype");
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
|
||||
.font-test {
|
||||
color: red;
|
||||
font-family: "CustomFont";
|
||||
}
|
||||
|
||||
|
||||
@font-face {
|
||||
font-family: "CustomOTFFont";
|
||||
src: url("/GoodHood-2.otf") format("opentype");
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
.font-otf {
|
||||
color: red;
|
||||
font-family: "CustomOTFFont";
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 56px;
|
||||
}
|
42
src/App.tsx
42
src/App.tsx
@ -1,12 +1,40 @@
|
||||
import "./App.css";
|
||||
import { createMemo, createSignal } from "solid-js";
|
||||
|
||||
function App() {
|
||||
const test = "ABCabc问藏书房令东齐伋复刻体";
|
||||
const [text, set_text] = createSignal("天地无极,乾坤借法");
|
||||
|
||||
const serverPath = import.meta.env.DEV ? "/" : "https://webfont.shenzilong.cn/";
|
||||
const style = createMemo(
|
||||
() => `
|
||||
@font-face {
|
||||
font-family: "CustomFont";
|
||||
src: url("${serverPath}api?font=令东齐伋复刻体.ttf&text=${text()}") format("truetype");
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
input {
|
||||
color: red;
|
||||
font-family: "CustomFont";
|
||||
}
|
||||
`,
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<p class="font-test">{test}</p>
|
||||
<p class="font-test2">{test}</p>
|
||||
<p class="font-otf">{test}</p>
|
||||
</>
|
||||
<div>
|
||||
<h1>
|
||||
<a href="https://github.com/2234839/web-font">web font</a>{" "}
|
||||
</h1>
|
||||
<div>
|
||||
<div>在下面输入文本查看效果</div>
|
||||
<input
|
||||
style={{ "font-size": "46px", "margin-top": "3px" }}
|
||||
value={text()}
|
||||
onInput={(e) => set_text(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<pre>{"<style>" + style() + "</style>"}</pre>
|
||||
<style>{style()}</style>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,68 +0,0 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
/* @refresh reload */
|
||||
import { render } from 'solid-js/web'
|
||||
|
||||
import './index.css'
|
||||
import App from './App'
|
||||
|
||||
const root = document.getElementById('root')
|
||||
|
@ -1,10 +1,17 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import solid from 'vite-plugin-solid'
|
||||
import { } from "fs";
|
||||
import { defineConfig } from "vite";
|
||||
import solid from "vite-plugin-solid";
|
||||
import {} from "fs";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [solid()],
|
||||
server:{
|
||||
host:"0.0.0.0"
|
||||
}
|
||||
})
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
proxy: {
|
||||
// with options
|
||||
"/api": {
|
||||
target: "http://localhost:8087",
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user