This commit is contained in:
手瓜一十雪 2025-03-26 12:27:43 +08:00
parent bccf5894cd
commit 31fdffde36
9 changed files with 22 additions and 5 deletions

BIN
external/fonts/AaCute.ttf vendored Normal file

Binary file not shown.

BIN
external/fonts/JetBrainsMono.ttf vendored Normal file

Binary file not shown.

BIN
external/fonts/post.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 KiB

4
src/plugin/data.ts Normal file
View File

@ -0,0 +1,4 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
export let current_path = dirname(fileURLToPath(import.meta.url));

View File

@ -1,4 +1,6 @@
import { createCanvas, loadImage } from "@napi-rs/canvas"; import { createCanvas, loadImage } from "@napi-rs/canvas";
import path from "path";
import { current_path } from "./data";
/** /**
* *
@ -41,7 +43,7 @@ export async function drawTimePattern(data: {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
// 加载背景图 // 加载背景图
const backgroundImage = await loadImage('C:\\fonts\\post.jpg'); const backgroundImage = await loadImage(path.join(current_path,'.\\fonts\\post.jpg'));
const pattern = ctx.createPattern(backgroundImage, 'repeat'); const pattern = ctx.createPattern(backgroundImage, 'repeat');
ctx.fillStyle = pattern; ctx.fillStyle = pattern;
ctx.fillRect(0, 0, width, height); ctx.fillRect(0, 0, width, height);

View File

@ -1,4 +1,6 @@
import { createCanvas, loadImage } from "@napi-rs/canvas"; import { createCanvas, loadImage } from "@napi-rs/canvas";
import path from "path";
import { current_path } from "./data";
interface NetworkNode { interface NetworkNode {
id: string; id: string;
@ -39,7 +41,7 @@ export async function drawWordNetwork(data: NetworkData): Promise<string> {
// 绘制背景 // 绘制背景
try { try {
const backgroundImage = await loadImage('C:\\fonts\\post.jpg'); const backgroundImage = await loadImage(path.join(current_path, '.\\fonts\\post.jpg'));
const pattern = ctx.createPattern(backgroundImage, 'repeat'); const pattern = ctx.createPattern(backgroundImage, 'repeat');
if (pattern) { if (pattern) {
ctx.fillStyle = pattern; ctx.fillStyle = pattern;

View File

@ -1,4 +1,6 @@
import { current_path } from "@/plugin/data";
import { createCanvas, loadImage } from "@napi-rs/canvas"; import { createCanvas, loadImage } from "@napi-rs/canvas";
import path from "path";
export async function drawJsonContent(jsonContent: string) { export async function drawJsonContent(jsonContent: string) {
const lines = jsonContent.split('\n'); const lines = jsonContent.split('\n');
@ -27,7 +29,7 @@ export async function drawJsonContent(jsonContent: string) {
const finalCanvas = createCanvas(width, height); const finalCanvas = createCanvas(width, height);
const finalCtx = finalCanvas.getContext('2d'); const finalCtx = finalCanvas.getContext('2d');
const backgroundImage = await loadImage('C:\\fonts\\post.jpg'); const backgroundImage = await loadImage(path.join(current_path,'.\\fonts\\post.jpg'));
const pattern = finalCtx.createPattern(backgroundImage, 'repeat'); const pattern = finalCtx.createPattern(backgroundImage, 'repeat');
finalCtx.fillStyle = pattern; finalCtx.fillStyle = pattern;
finalCtx.fillRect(0, 0, width, height); finalCtx.fillRect(0, 0, width, height);

View File

@ -1,5 +1,9 @@
import { dirname, join } from 'node:path';
import { NCoreInitShell } from './base'; import { NCoreInitShell } from './base';
import { GlobalFonts } from '@napi-rs/canvas'; import { GlobalFonts } from '@napi-rs/canvas';
GlobalFonts.registerFromPath('C:\\fonts\\JetBrainsMono.ttf', 'JetBrains Mono'); import { fileURLToPath } from 'node:url';
GlobalFonts.registerFromPath('C:\\fonts\\AaCute.ttf', 'Aa偷吃可爱长大的');
let current_path = dirname(fileURLToPath(import.meta.url));
GlobalFonts.registerFromPath(join(current_path, '.\\fonts\\JetBrainsMono.ttf'), 'JetBrains Mono');
GlobalFonts.registerFromPath(join(current_path, '.\\fonts\\AaCute.ttf', 'Aa偷吃可爱长大的'));
NCoreInitShell(); NCoreInitShell();

View File

@ -27,6 +27,7 @@ if (process.env.NAPCAT_BUILDSYS == 'linux') {
const UniversalBaseConfigPlugin: PluginOption[] = [ const UniversalBaseConfigPlugin: PluginOption[] = [
cp({ cp({
targets: [ targets: [
{ src: './external/fonts', dest: 'dist/fonts' },
{ src: './manifest.json', dest: 'dist' }, { src: './manifest.json', dest: 'dist' },
{ src: './src/core/external/napcat.json', dest: 'dist/config/' }, { src: './src/core/external/napcat.json', dest: 'dist/config/' },
{ src: './src/native/packet', dest: 'dist/moehoo', flatten: false }, { src: './src/native/packet', dest: 'dist/moehoo', flatten: false },
@ -50,6 +51,7 @@ const UniversalBaseConfigPlugin: PluginOption[] = [
const FrameworkBaseConfigPlugin: PluginOption[] = [ const FrameworkBaseConfigPlugin: PluginOption[] = [
cp({ cp({
targets: [ targets: [
{ src: './external/fonts', dest: 'dist/fonts' },
{ src: './manifest.json', dest: 'dist' }, { src: './manifest.json', dest: 'dist' },
{ src: './src/core/external/napcat.json', dest: 'dist/config/' }, { src: './src/core/external/napcat.json', dest: 'dist/config/' },
{ src: './src/native/packet', dest: 'dist/moehoo', flatten: false }, { src: './src/native/packet', dest: 'dist/moehoo', flatten: false },
@ -69,6 +71,7 @@ const FrameworkBaseConfigPlugin: PluginOption[] = [
const ShellBaseConfigPlugin: PluginOption[] = [ const ShellBaseConfigPlugin: PluginOption[] = [
cp({ cp({
targets: [ targets: [
{ src: './external/fonts', dest: 'dist/fonts' },
{ src: './src/native/packet', dest: 'dist/moehoo', flatten: false }, { src: './src/native/packet', dest: 'dist/moehoo', flatten: false },
{ src: './src/native/pty', dest: 'dist/pty', flatten: false }, { src: './src/native/pty', dest: 'dist/pty', flatten: false },
{ src: './napcat.webui/dist/', dest: 'dist/static/', flatten: false }, { src: './napcat.webui/dist/', dest: 'dist/static/', flatten: false },