多单位版国产化地质资料管理系统
zhai
2025-09-17 7a8a84577894b766a95c6cbfa5ac7b51e54ac242
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.zbooksoft.gdmis.common;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Description:
 * @Author: zhai
 * @Date: 2025/8/12
 **/
public class TscUtil {
    public static List<String> wrapText(String text, int maxWidth, int size) {
        List<String> lines = new ArrayList<>();
        String[] words = text.split("");
        StringBuilder currentLine = new StringBuilder();
        int currentWidth = 0;
 
        for (String word : words) {
            // 简单估算字符宽度(中文字符宽度为2,英文字符宽度为1)
            int wordWidth = word.matches("[\\u4e00-\\u9fa5]") ? 2 : 1;
            if (currentWidth + wordWidth > maxWidth) {
                lines.add(currentLine.toString());
                currentLine = new StringBuilder(word);
                currentWidth = wordWidth;
            } else {
                currentLine.append(word);
                currentWidth += wordWidth;
            }
        }
 
        if (currentLine.length() > 0) {
            lines.add(currentLine.toString());
        }
        if (lines.size() > size) {
            return lines.subList(0, size);
        }
 
        return lines;
    }
 
    public static int getTextLong(String text) {
        String[] words = text.split("");
        int currentWidth = 0;
        for (String word : words) {
            // 简单估算字符宽度(中文字符宽度为2,英文字符宽度为1)
            currentWidth += word.matches("[\\u4e00-\\u9fa5]") ? 2 : 1;
        }
        return currentWidth;
    }
 
    public static String replaceEnglishQuotesWithChinese(String text) {
        if (text == null || text.isEmpty()) {
            return text;
        }
 
        StringBuilder result = new StringBuilder();
        boolean isOpenQuote = true; // 标记当前应该是开引号还是闭引号
 
        for (char c : text.toCharArray()) {
            if (c == '"') {
                // 根据标记决定使用开引号还是闭引号
                result.append(isOpenQuote ? '“' : '”');
                // 切换状态
                isOpenQuote = !isOpenQuote;
            } else {
                result.append(c);
            }
        }
        return result.toString();
    }
}