Closed abu-irrational closed 5 months ago
There's nothing super special there. The code has a longer history, and greater usage in a different context. It just boils down to getting the content of the file into memory, and returning a pointer and length. At the most basic, a 'fopen' with a giant 'fread' can do the work, albeit somewhat wasteful.
On both Linux and Mac, there are 'mapped file' apis, so substituting in for those in the mapped file, is all that's needed. They are much smaller and simpler than what Windows does.
I'll play with the Linux one. I will probably eliminate filestreamer, because it's really not needed, and just focus on mappedfile.
Note, these are not formally a part of the API/library. They just exist as helpers in the app.
Hi William, finally I integrated Svgandme for Windows, Linux, MacOS. Well, it works ! For a cross-platform build,I added this file "mmapfile.h" for memory-mapped files (see attached file) mmapfile.h.txt
The usage is simple:
#include <svg.h>
#include "mmapfile.h"
....
mmapfile* mmap = mmapfile_open(filename);
if (mmap == nullptr) {
... error ....
return false;
}
SVGDocument* svgDoc = new SVGDocument(gFontHandler);
if (svgDoc == nullptr) {
... error...
mmapfile_close(mmap);
return false;
}
ByteSpan span = ByteSpan(mmap->start, mmap->length);
bool res = svgDoc->loadFromChunk(span);
mmapfile_close(mmap);
// TODO : currently loadFromChunk always returns true (that's bad!)
if (res == false) {
delete svgDoc;
.. error ..
return false;
}
... here svgDoc contains the parsed SVG .....
== I only used files from svgandme/svg, and changed some small parts ...
with
Finally I should find a solution for loading a minimal set of fonts on Linux, MacOS, but, as long as the SVG does not use fonts, it works !
This is great! I will make similar changes to the code to reflect your changes. And yah, fonts work great, even when there's no font... You just won't see any text, but it should not crash. writeChunkToFile, and varText, I can remove those, as they're not strictly needed, but convenient.
How can I use the FileStreamer interface and and particular the mappedfile.h, in a cross-platform way (Linux, MacOS) ?