How to obtain permissions when copying files linux 64 lazarus / 21-General ---------------------------------------------------------------------- jianwt · 2023-01-17 12:32 How to obtain permissions when copying files  linux 64 Copy a font to the '/usr/share/fonts/' directory. How can you succeed? Thank you. uses ... fileutil   srcFile:=ExtractFilePath(ParamStr(0))+ '/wt/A.ttf';   srcTarget := '/usr/share/fonts/win/A.ttf';     if CopyFile(srcFile,srcTarget) then     begin         ShowMessage('true');    //     end else     begin          ShowMessage('false');     end;  We have tried many methods, but we can't. ---------------------------------------------------------------------- KodeZwerg · 2023-01-17 12:40 It is unclear what method you are calling. Try that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  FileUtils....  // call somewhere FileUtils.CopyFile() Another approach can be made with a stream, load to stream and save from stream. ---------------------------------------------------------------------- MarkMLl · 2023-01-17 12:41 You appears to be using some sort of unix: please put the OS you're using and version of FPC etc. in the body of your message, and use code quoting. Short answer: you can't. Longer answer: several possibilities: * Run using sudo, or whatever equivalent your desktop environment provides. * Run setuid root, noting that some widget sets refuse to do that. * Allocate appropriate POSIX capabilities to the program. * Add the user to a group which can write to that directory. * Change the group ownership of that directory, expect that to cause issues elsewhere. * Read up on polkit, PAM etc. Details very much depend on your OS etc. MarkMLl ---------------------------------------------------------------------- TRon · 2023-01-17 12:45 @jianwt What on earth are you trying to accomplish ? Installing fonts system wide requires root privileges and there is no way in hell that a sane user allows such a program to obtain root privileges. You can install fonts in the user home directory. But if you do so you would still have to update the font-cache. ---------------------------------------------------------------------- jianwt · 2023-01-17 13:35 @TRon linux, which uses FastReport to print reports, requires an off-system font. This installation itself stumped me. I didn't know how to do it. @TRon“You can install fonts in the user home directory. But if you do so you would still have to update the font-cache.” How to do it ? thank you. ---------------------------------------------------------------------- winni · 2023-01-17 15:01 Quote from: jianwt on January 17, 2023, 02:35:02 pm. But if you do so you would still have to update the font-cache.” How to do it ? thank you. as root:Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   fc-cache -f -v Winni ---------------------------------------------------------------------- TRon · 2023-01-17 23:56 Quote from: jianwt on January 17, 2023, 02:35:02 pmlinux, which uses FastReport to print reports, requires an off-system font. This installation itself stumped me. I didn't know how to do it. I am not familiar with FastReport but I do know it is possible to embed fonts in an application (without the need to install them). A quick search for FastReport directed me to https://www.fast- report.com/en/blog/show/fonts-reports-without-installing/ I did not have a look at the provided answer but perhaps it is able to help you understand the situation. QuoteHow to do it ? As perfectly explained by user winni just a generic note: On Linux it is frowned upon if a program just install fonts. Usually it is the user that (sometimes very carefully) decides which fonts to install. If a program requires special fonts then it is usually a dependency fo the package of your program or the program package itself installs the fonts. It will never be the application itself that install fonts (unless your program is a (system) font manager of some sort). ---------------------------------------------------------------------- jianwt · 2023-01-18 01:29 I do know FastReport. NET is possible to embed fonts in an application。 ---------------------------------------------------------------------- dbannon · 2023-01-18 04:34 Have a read of https://linuxconfig.org/how-to-install-and-manage- fonts-on-linux notes : my system wide config file includes ~/.fonts and my fc-cache command does not require root access. But that could well depend on which Linux you are using. Mark asked you that for a good reason. Personally, I have used ~/.fonts in the past, not recently, but never had any problems. And I strongly endorse what TRon said. Davo ---------------------------------------------------------------------- MarkMLl · 2023-01-18 07:12 I'd add that while I believe it is possible to embed a font in an executable or .dll on Windows, I don't believe it's possible to do so on Linux. However the hack mentioned earlier of using a .pdf is obviously interesting. MarkMLl ---------------------------------------------------------------------- Thaddy · 2023-01-18 07:23 It is also possible on linux, because the mechanism for resources in Lazarus is the same on all platforms, although (somewhat recent) the mechanism is based on Windows. Simply use FONT (or RCDATA) to store the font in an rc/res. e.g.Code: [Select]5 FONT  "cmroman.fnt"You can subs. use the font by loadfromresource. ---------------------------------------------------------------------- MarkMLl · 2023-01-18 07:32 Thanks for that, I was trying to be cautious in case OP made any unjustified assumptions. Is that completely transparent, i.e. the font appears in an app's font selector etc.? MarkMLl ---------------------------------------------------------------------- Thaddy · 2023-01-18 07:36 Quote from: MarkMLl on January 18, 2023, 08:32:22 amThanks for that, I was trying to be cautious in case OP made any unjustified assumptions. Is that completely transparent, i.e. the font appears in an app's font selector etc.? MarkMLl No the latter is not true, that accesses the font directory on the platforms and does not know about the font resource. I editted my first post somewhat with an example from msdn. What is possible, though, is to save the font from the resource into the font directory, but that requires elevated rights on nixes, I believe, not sure. Then it would show up in a font selector. Linux: /usr/share/fonts , /usr/local/share/fonts or ~/. fonts Windows: \windows\fonts [edit] Under Linux, the ~/.fonts hidden directory does not require elevation. Depending on distribution the other two might require administrative rights. ---------------------------------------------------------------------- jianwt · 2023-01-18 09:27 I created the directory '.fonts' in linux '~/' and copied the needed fonts. In the software, these fonts will work. However, I am not sure if this method will work in all LINUX systems. ---------------------------------------------------------------------- Thaddy · 2023-01-18 09:42 Yes they will, otherwise it is not Linux. But note that for your specifics it may be still better to embed the font in a resource. ---------------------------------------------------------------------- MarkMLl · 2023-01-18 09:43 Quote from: jianwt on January 18, 2023, 10:27:10 amI created the directory '.fonts' in linux '~/' and copied the needed fonts. In the software, these fonts will work. However, I am not sure if this method will work in all LINUX systems. This isn't a Linux issue per se, but will depend on your distro etc. and possibly on the widget set. You've not told us precisely what you're using, so you're on your own. MarkMLl ---------------------------------------------------------------------- Thaddy · 2023-01-18 09:51 Well, not exactly. The directories I mentioned will be obeyed by any Linux distribution. ---------------------------------------------------------------------- MarkMLl · 2023-01-18 10:15 I'm just being cautious here: it's safer to say "don't rely on this until you've worked out whether it's actually there" than to say "this will work" and have the support burden if it doesn't work because it's not there. I've been checking over the last few minutes, and I've definitely got a system here which doesn't have fc-cache so I wouldn't like to specify what it's on. It's from Fontconfig which is apparently from Freedesktop.org, but inclusion might turn out to be universal after a certain date or might turn out to be distro-specific. Another potentially problematic scenario is when there's more than one computer involved, i.e. one running the program and another actually displaying the application window. Under those conditions, it's unhelpful for the program to rely on what's in the ~/.fonts that it can see, since the files that actually matter are the ones on the system running the X11 server in front of the user. That's where the X Font Server is- or at least used to be- relevant. MarkMLl ---------------------------------------------------------------------- PascalDragon · 2023-01-18 21:31 Quote from: Thaddy on January 18, 2023, 08:23:29 amIt is also possible on linux, because the mechanism for resources in Lazarus is the same on all platforms, although (somewhat recent) the mechanism is based on Windows. Simply use FONT (or RCDATA) to store the font in an rc/res. e.g.Code: [Select]5 FONT  "cmroman.fnt"You can subs. use the font by loadfromresource. Embedding a font as a resource does not mean that the font will be easily usable by the application. E.g. Qt relies solely on a correctly configured FontConfig on non-macOS *nix systems to retrieve fonts. And thus one needs to add fonts to the font directories configured there. Quote from: Thaddy on January 18, 2023, 10:51:13 amWell, not exactly. The directories I mentioned will be obeyed by any Linux distribution. Only if FontConfig is configured as such. Nothing stops the system administrator from disabling the per-user font directories if they feel like it.