首页 > 系统相关 >Linux下用lazarus编写的软件安装自带字体到指定文件夹

Linux下用lazarus编写的软件安装自带字体到指定文件夹

时间:2023-01-28 16:11:53浏览次数:58  
标签:SubDirStructure fonts SourceDir FinalisedDestDir 下用 FilesFoundToCopy lazarus 字体 

lazarus使用报表时遇到某些电脑缺少字体,造成打印出来的效果有差异,为避免这个问题,可以手工安装字体,也可以用程序拷贝字体到指定的文件夹(/usr/share/fonts或~/.local/share/fonts),如果拷贝到~/.local/share/fonts程序不需要root权限,以下代码将应用程序font目录的所有ttf字体文件拷贝到~/.local/share/fonts
直接上代码:

uses FileUtil,LazFileUtils;//要添加这2个单元
procedure TForm1.CopyDirFile(const SourceDirName,DestDir: string);
var
  i, j: integer;
  FilesFoundToCopy : TStringList;
  SourceDirectoryAndFileName, SubDirStructure, FinalisedDestDir, FinalisedFileName : string;
  SourceDir:string;
begin
  SourceDir:= SourceDirName;
  SubDirStructure := '';
  FinalisedDestDir := '';

  SetCurrentDir(SourceDirName);
  FilesFoundToCopy := FindAllFiles(SourceDirName, '*', True);

  try
    for i := 0 to FilesFoundToCopy.Count -1 do
    begin
      SourceDirectoryAndFileName := ChompPathDelim(CleanAndExpandDirectory(FilesFoundToCopy.Strings[i]));

      SubDirStructure := IncludeTrailingPathDelimiter(ExtractFileDir(SourceDirectoryAndFileName));
      if SourceDir+'/'=SubDirStructure then SubDirStructure:='';
      j:= pos(SourceDir,SubDirStructure)+length(SourceDir);
      if pos(SourceDir,SubDirStructure)>0 then
         SubDirStructure:=Copy(SubDirStructure, j,length(SubDirStructure));

      FinalisedDestDir :=DestDir+SubDirStructure;
      FinalisedFileName := ExtractFileName(FilesFoundToCopy.Strings[i]);

      if not DirPathExists(FinalisedDestDir) then
      begin
        ForceDirectories(FinalisedDestDir);
      end;

      if (pos('.ttf',SourceDirectoryAndFileName)>0) then//只拷贝ttf字体文件
        FileUtil.CopyFile(SourceDirectoryAndFileName, FinalisedDestDir+FinalisedFileName, true);
    end;
  finally
    FilesFoundToCopy.free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);

begin
  //只拷贝程序font文件夹的所有ttf字体文件
  CopyDirFile(ExtractFilePath(ParamStr(0))+'font/',ConcatPaths([GetUserDir, '.local', 'share', 'fonts'])+'/');
end;
      

 

标签:SubDirStructure,fonts,SourceDir,FinalisedDestDir,下用,FilesFoundToCopy,lazarus,字体,
From: https://www.cnblogs.com/qiufeng2014/p/17070514.html

相关文章

  • linux下core file size设置笔记
    现象说明:突然发现一台测试机器的java程序莫名其妙地没了,但是没有coredump!这就需要打开服务器的core文件生成的功能了,(即coredump文件),方便程序调试。1)core文件简介core......
  • linux yum 命令错误常见记录
    [root@localhost~]#wget-O/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-7.repo......
  • 使用备份和还原将 SQL Server 数据库从 Windows 迁移到 Linux
    建议使用SQLServer的备份和还原功能将数据库从Windows上的SQLServer迁移到Linux上的SQLServer。在本教程中,将逐步完成使用备份和还原方法将数据库迁移到Linu......
  • Linux系统编程-文件IO
    文件IO标准库IO函数和linux系统调用IO函数的区别:标准C库的文件IO函数是跨平台的,在不同的平台上调用不同的系统API标准C库的IO函数有缓冲区,而linux系统调用的没有缓......
  • linux安装nginx
    一、安装准备(参考https://tech.powereasy.net/cpzsk/wzfwqwlaq/content_23804)1. 离线安装需要依赖GCC,通过以下命令可以检查GCC是否安装gcc–version银河麒麟是系统默......
  • DELL OpenManage Server Administrator (OMSA) for Linux安装
    1.下载和安装软件包从Dell官网(选择对应的机器和操作系统版本)下载DellOpenManageServerAdministrator软件包: 以下步骤是在DellR730和redhat7.5上运行的案例:1.使......
  • linux基本命令
    tail-1000fxx.out  实时查看文件catxx.out 查看文件more查看全部内容pwd 查看当前位置rm删除 rm-rf删除任何文件touch 创建文件grep过滤 参考:......
  • linux基础设置
    1、修改主机hostnamevi/etc/hostname修改hostsvi/etc/hosts192.168.10.201cdh201192.168.10.202cdh202192.168.10.203cdh203192.168.10.204cdh204重启电......
  • Linux find 命令
    Linuxfind命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与......
  • netstat 网络连接(Linux)
    netstat网络连接(Linux)一、前言基于tcp或udp的应用程序启动后,想要查看程序对应的端口号是否打开。netstat是一个告诉我们操作系统中所有tcp/udp/unixsocket连接状......