Skip to content

Conversation

jtanx
Copy link
Contributor

@jtanx jtanx commented May 29, 2015

Some work towards fixing #2290. Also fixes some other bugs along the way.

General direction: Use GLib for all actions that require interaction with the filesystem (still a long long way to go here) where possible.
Rationale: GLib properly handles unicode filenames (on Windows you give it a UTF-8 filename and it does the rest). It's way too much effort to have a separate codepath just for Windows.


This PR includes:

  • Fixing compiler warnings about collab code (use of g_signal_new). Requires testing by someone who uses collab.
  • Ignore more files from git history (ltargz.m4, uthash)
  • Removal of mkdir_p (use g_mkdir_with_parents) and smprintf (use xasprintf)
  • Replace usage of opendir with GLib equivalents (this is still ongoing)
    • The file browser can now show Unicode filenames properly. You probably still can't open them though.
  • Fix bug in the autosave recover function on Windows. (Previously if you selected one of the 'Forget' options, it wouldn't forget the file because of an open file handle preventing deletion)
  • Fixing bug in saving hotkeys on Windows (for much the same reason as the autosave bug)
  • Getting rid of fork/exec in autotrace and using g_spawn_sync instead. This removes the Windows specific code path.
  • Porting the MetaFont import functionality to Windows. You need a LaTeX distribution installed (e.g. MikTeX) for this to work. Probably also fixed this process for files with spaces in their names.

cc @frank-trampe

jtanx added 3 commits May 26, 2015 11:44
This allows for the correct browsing of files with unicode characters on Windows.
…ases.

Also: In preparation for UTF-8 fopen on MINGW/Windows. (Patching gnulib)
Note: It turns out the gnulib implementation of select/send/recv
causes the UI to be treacle slow (gxdraw.c). So don't use that.
@larsenwork
Copy link

I'm no windows and/or colab user but just wanted to say 👍 on the work

@jtanx jtanx force-pushed the unidir branch 2 times, most recently from 695f3d8 to 8a0191e Compare May 29, 2015 13:17
@jtanx
Copy link
Contributor Author

jtanx commented May 29, 2015

Thanks.

I've briefly tested the collab and autotrace code on Linux, and I don't think there's any (introduced) bugs caused by this. I did fix one segfault bug in the collab code that was unrelated to these changes.

P.S: I notice the collab server doesn't close by itself when FontForge closes... I don't think this is caused by me though.

jtanx added 5 commits May 29, 2015 22:59
Remove unused parameter from collab signal

The segfault discovered is unrelated to this issue though.
This is part of a portability requirement for working with Unicode filenames
on Windows.
On Windows, you can only unlink a file that has no open file handles.
So do `fclose` before `unlink`.
This fixes the message:
> Failed to rename the new hotkeys file over your old one!
> Reason:File exists

Reason: 'rename' on Windows is not atomic, and nor will it rename if the
destination file exists. Cygwin seems to handle this internally, so this is
MINGW specific.
jtanx added 2 commits May 30, 2015 08:51
Also: Move ProgramExists->GFileProgramExists (into gutils/fsys.c)

Refactoring the autotrace code
Ported using g_spawn_sync as before for autotrace.

NB: Not using g_close because it only exists in GLib 2.36, and we can't use
g_close on Windows anyway (which is the only platform where this would matter).

Add in header for close
@frank-trampe
Copy link
Contributor

I expect to have sometime to look at this on Wednesday.

All the prototypes in `fileutil.h` already exist in `gfile.h`.
@jtanx
Copy link
Contributor Author

jtanx commented May 31, 2015

I have switched over all remaining uses of opendir to the GLib equivalents (except in acorn2sfd.c which appears to be a separate program in itself).

I also removed the header fileutil.h, which was redundant, given that all the function prototypes in it already existed in gfile.h.

@@ -7612,7 +7606,7 @@ return( NULL );
free(filename);

/* Check if the file exists and is readable */
if ( access(locfilename,R_OK)!=0 ) {
if ( GFileReadable(locfilename) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, should be !GFileReadable

Something should be done about the number of character conversion functions
available...
@jtanx
Copy link
Contributor Author

jtanx commented Jun 1, 2015

Hmm, just going through, why was 5360843 done again? The functions in usprintf are still unused.

@adrientetar
Copy link
Member

Too often (I mean in general, not FontForge specifically) I see reverted commits without explanatory comment. IMO one should always explain why the revert in the log.

It does all the original code did, plus it actually works on Windows.
@jtanx jtanx mentioned this pull request Jun 2, 2015
@@ -640,4 +640,4 @@ char *utf82def_copy(const char *ufrom) {
ret = u2def_copy(u2from);
free(u2from);
return( ret );
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we dropping the trailing linebreak?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that wasn't intentional.

jtanx added 3 commits June 6, 2015 08:52
On Windows, this allows e.g. Cyrillic keyboards to work even if Cyrillic is
not currently the active codepage.

Related issues: fontforge#1729, fontforge#2290
@@ -25,26 +25,22 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "fontforgevw.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big diff. Would you outline the changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the comments I made earlier, but briefly:

  • Get rid of the Windows specific code path by switching to using GLib
  • Port the MetaFont importing function to Windows

@frank-trampe
Copy link
Contributor

@jtanx, I'm not sure about switching every file call to use GLib. It seem ridiculous to me that all of the standard library file handling functions would be broken on Windows. Surely there are other pieces of software that work correctly on Windows using the standard calls (perhaps via some changes to the compilation process)?

@jtanx
Copy link
Contributor Author

jtanx commented Jun 11, 2015

@frank-trampe if you want to support opening files with Unicode filenames, GLib is the easiest way. On Windows, all the standard C library functions assume what is called the multi-byte version of functions.

What this means is that they expect filenames (and all other strings for that matter) to be in what is known as the 'current active codepage' - but this is independent of how filenames are represented, so you can always have the case that a particular filename that cannot be represented by the current active codepage.

If you look at the Microsoft documentation for say fopen, you'll notice that there is a 'wide-character' version that expects the filename to be encoded in UTF-16 - being Unicode, it works with all filenames.

It is for this very reason that internally, GLib must mandate that all strings on Windows for filenames are UTF-8 encoded, and internally they do the re-encode to UTF-16 and then call the wide character version of the functions.

For the greatest portability, I think FontForge should be looking into using more of GLib and not less.

@jtanx
Copy link
Contributor Author

jtanx commented Jun 14, 2015

@frank-trampe I plan on splitting this PR to make things easier to merge.

@jtanx jtanx changed the title Multiple fixes Increase GLib usage for better handling of filenames and increased portability Jun 15, 2015
@jtanx jtanx changed the title Increase GLib usage for better handling of filenames and increased portability Multiple fixes Jun 15, 2015
@jtanx jtanx closed this Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants