原因不在于doxygen,它没有问题,问题出在微软的HTML Help Workshop的hhc.exe不支持utf8.所以要解决这个问题,需要做两个额外的步骤:

1.将html/index.hhp中的Language=0x409 English (United States)换成Language=0x804 中文 (中国),并将文本存成UTF8格式。

2.将html/index.hhc整个文件从UTF8编码换成gb2312,再次手动调用hhc.exe去处理这个hhp文件即可生成不是乱码的中文chm帮助文档。

我自己用C#写了个小工具来处理这个过程,源代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics; namespace Generator
{
class Program
{ static void Main(string[] args)
{
if(args.Length <=)
{
Console.WriteLine("Error:缺少目标配置文件");
return;
} string path = args[]; if(!File.Exists(path))
{
Console.WriteLine(string.Format("{0}不存在", path));
return;
} using(ChmGenerator generator = new ChmGenerator(path))
{
generator.Generate();
}
}
} public class ChmGenerator : IDisposable
{
static readonly string HHC_CONFIG_LOCATION = "HHC_LOCATION = \"C:/Program Files (x86)/HTML Help Workshop/hhc.exe\""; string WorkDirectory;
string InputFile;
string ConfigText;
string NewHHCConfig;
string NewConfigText;
string NewConfigPath; string HHCLocation;
string DoxygenPath; string IntermediatePath;
string IntermediateHHP;
string IntermediateHHC; public ChmGenerator(string inputFile)
{
InputFile = inputFile; string Directory = Path.GetDirectoryName(InputFile);
WorkDirectory = Directory; System.IO.Directory.SetCurrentDirectory(WorkDirectory); HHCLocation = Path.Combine(Directory, "hhc.exe");
DoxygenPath = Path.Combine(Directory, "doxygen.exe");
IntermediatePath = Path.Combine(Directory, "Intermediate");
IntermediateHHP = Path.Combine(IntermediatePath, @"html/index.hhp");
IntermediateHHC = Path.Combine(IntermediatePath, @"html/index.hhc");
NewHHCConfig = string.Format("HHC_LOCATION = \"{0}\"", HHCLocation);
} public void Dispose()
{
try
{
if (!string.IsNullOrEmpty(NewConfigPath) && File.Exists(NewConfigPath))
{
File.Delete(NewConfigPath);
}
}
finally
{ }
} public void Generate()
{
ConfigText = File.ReadAllText(InputFile, Encoding.UTF8); NewConfigPath = Path.Combine(WorkDirectory, Guid.NewGuid().ToString() + ".doxygenProj");
NewConfigText = ConfigText.Replace(HHC_CONFIG_LOCATION, NewHHCConfig); File.WriteAllText(NewConfigPath, NewConfigText, Encoding.UTF8); // 调用doxygen来生成
StartProc(DoxygenPath, string.Format(" {0}", NewConfigPath)); if(!PrepareInputFiles())
{
Console.WriteLine("无法正确生成chm");
return;
} // 调用hhc生成chm
StartProc(HHCLocation, string.Format(" {0}", IntermediateHHP)); } private bool PrepareInputFiles()
{
// 替换Language
if (File.Exists(IntermediateHHP))
{
ReplaceFileText(IntermediateHHP, "Language=0x409 English (United States)", "Language=0x804 中文 (中国)", Encoding.UTF8); if (File.Exists(IntermediateHHC))
{
ChangeFileToAnsi(IntermediateHHC, Encoding.UTF8, Encoding.GetEncoding("gb2312")); return true;
}
else
{
Console.WriteLine(string.Format("Error:{0}不存在", IntermediateHHC));
}
}
else
{
Console.WriteLine(string.Format("Error:{0}不存在", IntermediateHHP));
} return false;
} private void ChangeFileToAnsi(string inputPath, Encoding sourceEncoding, Encoding destEncoding)
{
var text = File.ReadAllText(inputPath, sourceEncoding);
byte[] bytes = sourceEncoding.GetBytes(text); // convert to win bytes
var destBytes = Encoding.Convert(
sourceEncoding, destEncoding, bytes); File.WriteAllBytes(inputPath, destBytes);
} private void ReplaceFileText(string inputPath, string sourceText, string destText, Encoding encoding)
{
var text = File.ReadAllText(inputPath, Encoding.UTF8);
text = text.Replace(sourceText, destText);
File.WriteAllText(inputPath, text, encoding);
} static void StartProc(string application, string command)
{
Debug.Assert(File.Exists(application)); var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = application,
Arguments = " " + command,
RedirectStandardOutput = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8
}
}; process.Start(); while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine(); Console.WriteLine(line);
// Debug.WriteLine(line);
} process.WaitForExit();
}
}
}

另外为了确保目标机器没有安装doxygen或者hhc都不影响我生成文档,因此我将这些执行档都复制了一份放到了doxygen项目下,代码中的一些额外步骤就是强行将原始project文件中的hhc路径改成当前目录下的hhc。

目录结构如下:

遇到doxygen生成的chm文档目录如果有中文是乱码?的更多相关文章

  1. 使用Doxygen生成net帮助文档

    一. 什么是Doxygen? Doxygen 是一个程序的文件产生工具,可将程序中的特定批注转换成为说明文件.通常我们在写程序时,或多或少都会写上批注,但是对于其它人而言,要直接探索程序里的批注,与打 ...

  2. 使用Doxygen生成C#帮助文档

    一. 什么是Doxygen? Doxygen 是一个程序的文件产生工具,可将程序中的特定批注转换成为说明文件.通常我们在写程序时,或多或少都会写上批注,但是对于其它人而言,要直接探索程序里的批注,与打 ...

  3. Doxygen生成美丽注释文档(1):初体验

    Chapter 1 - 准备工作 (Windows环境) 1.1 程序包下载 1. Doxygen * 源码: git clone https://github.com/doxygen/doxygen ...

  4. YUIDoc example代码高亮错误、生成API文档目录不按源文件注释顺序

    1.如果发现yuidoc命令用不了,那就重装nodejs吧 昨天不知道是清扫电脑的原因,yuidoc命令用不了(命令不存在),也没有找到好的解决方法,怒重装YUIDoc也不行.最后想了想,怒重装了no ...

  5. 制作Aspose CHM文档的过程记录

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  6. 用doxygen风格注释代码生成文档

    目录 用doxygen风格注释代码生成文档 1. 说明 2. 具体操作 2.1 生成头部注释 2.2 安装doxygen 2.3 工程配置 3. 总结 用doxygen风格注释代码生成文档 1. 说明 ...

  7. 安装doxygen(一个自动文档生成工具)+Graphviz图形可视化软件

    参考文章: http://www.fmddlmyy.cn/text21.html http://www.cnblogs.com/duguguiyu/archive/2008/06/29/1231852 ...

  8. 生成chm文档工具- Sandcastle -摘自网络

    Sandcastle是微软官方的文档生成工具,NDoc开发停止后,这个貌似也是唯一的一个这方面的工具.它从dll文件及其xml注释文件能够 生成完整的帮助文档,支持多种生成格式(Helpe1x:chm ...

  9. IDEA生成doc文档-生成chm文档

    首先,打开IDEA,并找到Tools -> Generate JavaDoc- 可供查询的chm比那些HTML页面好看多了. 如果您用过JDK API的chm文档,那么您一定不会拒绝接受其它第三 ...

随机推荐

  1. day7.关于字符串的相关操作

    一.字符串的相关操作 """ (1)字符串的拼接 (2)字符串的重复 (3)字符串跨行拼接 (4)字符串的索引 (5)字符串的切片: 语法 => 字符串[::] 完 ...

  2. 实验06——java自动封箱、自动拆箱

    package cn.tedu.demo; /** * @author 赵瑞鑫 E-mail:1922250303@qq.com * @version 1.0 * @创建时间:2020年7月17日 上 ...

  3. Hotspot GC研发工程师也许漏掉了一块逻辑

    本文来自: PerfMa技术社区 PerfMa(笨马网络)官网 概述 今天要说的这个问题,是我经常面试问的一个问题,只是和我之前排查过的场景有些区别,属于另外一种情况.也许我这里讲了这个之后,会成为不 ...

  4. BiMPM:Bilateral Multi-Perspctive Matching for Natural Language Sentences

    导言 本论文的工作主要是在 'matching-aggregation'的sentence matching的框架下,通过增加模型的特征(实现P与Q的双向匹配和多视角匹配),来增加NLSM(Natur ...

  5. 读源码从简单的集合类之ArrayList源码分析。正确认识ArrayList

    一.查看源码的方法 1.看继承结构 看这个类的层次结构,处于一个什么位置,可以在自己心里有个大概的了解. 我是有idea查看的, eg:第一步: 第二步: 第三步:查看子类或者继承关系:F4 2.看构 ...

  6. Docker 阿里镜像

    Docker 配置阿里镜像 Dokcer 拉取镜像非常慢,配置阿里镜像加速. 步骤 首先注册阿里云,找到 "容器镜像服务" --> "镜像加速器" ,复制 ...

  7. PYTHON实战完整教程1-配置VSCode开发环境

    一.安装 为降低学习门槛,保证学习目标的聚焦,我们在windows(使用WinServer2019虚拟机)上搭建开发环境.(系列教程最后结束时,也会部署到linux上) 打开Python官网 http ...

  8. one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3, 1280, 28, 28]], which is output 0 of LeakyReluBackward1, is at version 2;

    RuntimeError: one of the variables needed for gradient computation has been modified by an inplace o ...

  9. ElasticSearch 7.8.1 从入门到精通

    学前导读 ElasticSearch对电脑配置要求较高,内存至少4G以上,空闲2G内存,线程数4018+ 学习的时候,推荐将ElasticSearch安装到Linux或者mac上,极度不推荐装Wind ...

  10. Java中的File类,递归是什么?

    一.IO概述 当需要把内存中的数据存储到持久化设备上这个动作称为输出(写)Output操作. 当把持久设备上的数据读取到内存中的这个动作称为输入(读)Input操作. 因此我们把这种输入和输出动作称为 ...