diff --git a/.vscode/settings.json b/.vscode/settings.json index 1a40391..9e551c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,4 +22,11 @@ "pasteImage.path": "${currentFileDir}/images", "pasteImage.showFilePathConfirmInputBox": true, "prettier.singleQuote": false, + "spellright.language": [ + "zh-CN" + ], + "spellright.documentTypes": [ + "latex", + "plaintext" + ], } diff --git a/java/AWT-TextRender.md b/java/AWT-TextRender.md new file mode 100644 index 0000000..65e3ba7 --- /dev/null +++ b/java/AWT-TextRender.md @@ -0,0 +1,91 @@ +--- +tags: #java.awt #Graphics2D #TextRender +--- + +# Graphics2D 绘制文字 + +本文主要记录使用 `Graphics2D` 进行文本渲染相关内容。 + +## 参考代码 + +```java +package com.test.testImage; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.File; + +import javax.imageio.ImageIO; + +public class Graphics2DTest { + + public static void main(String[] args) { + try { + String text = "文字居中"; + int width = 500; + int height = 400; + // 创建BufferedImage对象 + BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); + // 获取Graphics2D + Graphics2D g2d = image.createGraphics(); + // 设置背景色 + g2d.setBackground(new Color(255,255,255)); + //g2d.setPaint(new Color(0,0,0)); + // 设置前景色 + g2d.setColor(Color.red); + // 绘制填充矩形 填充背景 + g2d.clearRect(0, 0, width, height); + // 载入字体 + Font font=new Font("宋体",Font.PLAIN,64); + // 设置字体 + g2d.setFont(font); + // 设置抗锯齿 + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + // 计算文字长度,计算居中的x点坐标 + // 获取字体度量参数 + FontMetrics fm = g2d.getFontMetrics(font); + // 测量文本长度 + int textWidth = fm.stringWidth(text); + // 获得文本居中的起点x位置 + int widthX = (width - textWidth) / 2; + // 表示这段文字在图片上的位置(x,y) .第一个是你设置的内容。 + g2d.drawString(text,widthX,100); + // 释放对象 + g2d.dispose(); + // 保存文件 + ImageIO.write(image, "jpg", new File("D:/test.jpg")); + } + catch(Exception ex) { + ex.printStackTrace(); + } + } +} +``` + +## 图像缓冲区 +```java +BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); +Graphics2D g2d = image.createGraphics(); +``` + +## 抗锯齿 +```java +g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); +``` + +## 测量文本 +```java +// 获取字体度量参数 +FontMetrics fm = g2d.getFontMetrics(font); +// 测量文本长度 +int textWidth = fm.stringWidth(text); +``` + +## 导出文件 +```java +ImageIO.write(image, "jpg", new File("D:/test.jpg")); +``` \ No newline at end of file diff --git a/java/AWT.md b/java/AWT.md new file mode 100644 index 0000000..d5b6b21 --- /dev/null +++ b/java/AWT.md @@ -0,0 +1,13 @@ +--- +tags: #java.awt #Graphics2D +--- +# java.awt + +`AWT` 全称 `Abstract window toolkit` `抽象窗口工具包`,提供了一组丰富的平台无关的方式来创建图形用户界面的库。 + +本人并不关心其用于制作用户界面的部分,主要使用它的图形库进行图像渲染,因此笔记中不会记录窗口或者控件之类的内容,仅记录渲染功能。 + +有用的链接: + +- [API Reference: Package java.awt](https://www.apiref.com/java11-zh/java.desktop/java/awt/package-summary.html) AWT包的接口中文参考文档 + diff --git a/rust/bore.md b/rust/bore.md new file mode 100644 index 0000000..7b571f5 --- /dev/null +++ b/rust/bore.md @@ -0,0 +1,73 @@ +--- +tags: #rust #network #bore +--- + +# [bore](https://github.com/ekzhang/bore) +`Rust` 中的一个现代、简单的 `TCP` 隧道,它将本地端口暴露给远程服务器,绕过标准 `NAT` 。这就是它所做的一切:不多也不少。 + +## 安装 +> 需要有rust环境,rust环境安装参照 [[install-rust]] 。 +```bash +cargo install bore-cli +``` +*安装的时候会从 `github` 拉 `crates.io-index` ,要上 `github` 啊,可恶,根本上不去。* + + +## 服务端使用 +先在云服务器把防火墙打开想要开放的端口,以及开放 `bore` 的对外端口 `7835`。 + +客户端是通过连接 `7835` 来进行握手,然后才从其它端口建立连接。 + +然后直接运行 `bore server` 就可以开始监听了。 +``` +$ bore server +2022-04-21T07:08:49.256539Z INFO bore_cli::server: server listening addr=0.0.0.0:7835 +``` + + +## 客户端使用 +确认要映射的端口,服务端地址 +``` +$ bore local 22 --to hostname +``` +直接这样连的话,端口是随机分配的,要指定端口需要使用 `--port ` 命令行参数。 +``` +$ bore local 22 --to jie65535.top --port 9022 +2022-04-21T09:11:39.835236Z INFO bore_cli::client: connected to server remote_port=9022 +2022-04-21T09:11:39.835322Z INFO bore_cli::client: listening at jie65535.top:9022 +``` + +## 服务端帮助 +``` +bore-server 0.3.0 +Runs the remote proxy server + +USAGE: + bore server [OPTIONS] + +OPTIONS: + -h, --help Print help information + --min-port Minimum TCP port number to accept [default: 1024] + -s, --secret Optional secret for authentication [env: BORE_SECRET] + -V, --version Print version information +``` + +## 客户端帮助 +``` +bore-local 0.3.0 +Starts a local proxy to the remote server + +USAGE: + bore local [OPTIONS] --to + +ARGS: + The local port to expose + +OPTIONS: + -h, --help Print help information + -l, --local-host The local host to expose [default: localhost] + -p, --port Optional port on the remote server to select [default: 0] + -s, --secret Optional secret for authentication [env: BORE_SECRET] + -t, --to Address of the remote server to expose local ports to + -V, --version Print version information +``` \ No newline at end of file diff --git a/rust/install-rust.md b/rust/install-rust.md new file mode 100644 index 0000000..5d0fe50 --- /dev/null +++ b/rust/install-rust.md @@ -0,0 +1,34 @@ +--- +tags: #rust +--- +# 安装Rust环境 + +从`https://sh.rustup.rs`获取安装脚本,执行脚本安装 + +```bash +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +source $HOME/.cargo/env && rustup default nightly && rustup update +``` + +建议切换到`nightly`通道,更新使用。 + +--- + +## 更换国内源 +使用时发现它还得上github获取索引,如果访问github有困难,可以换源。 +在 `~/.cargo/` 目录下 `touch config`,添加如下内容: +``` +[source.crates-io] +registry = "https://github.com/rust-lang/crates.io-index" +replace-with = 'ustc' +[source.ustc] +registry = "https://mirrors.ustc.edu.cn/crates.io-index" +``` +就可以更改为国内源 + +要通过系统 `git` 访问 `github` 的话,还可以加上以下内容 +``` +[net] +git-fetch-with-cli = true +``` +如果有 `Cargo` 不支持的特殊身份验证要求,将其设置为 `true` 会很有帮助。否则会使用 `cargo` 自带的 `git`。 \ No newline at end of file