How to load CanvasSvgDocument from file?












0















In a C++/winrt project I have a large number of small svg resources to be loaded from file. Since it would be slow to reload them all from disk at each CreateResources event from the CanvasVirtualControl I have loaded them in advance and stored the data for each in an array. When CreateResources happens my intent is to load a CanvasSvgDocument for each of these by using the CanvasSvgDocument method LoadFromXml(System.string). However, If I create an svgDocument using the resourcecreator, I get an invalid argument crash when calling LoadFromXml(). The resourceCreator argument looks right (VS preview 6 now allows me to see local variables!) and the xml data string argument looks like the valid svg data, so my best guess about the crash is that the data string is the wrong format. The file data is UTF-8. If I convert that to a std::wstring as I must for the LoadFromXml argument can it still be understood as byte data?
For example, I create the std::wstring this way, given a pointer to unsigned char file data and its length in bytes:



m_data_string = std::wstring(data, data + dataLength);


When CreateResources is triggered that datastring is referenced this way:



m_svg = CanvasSvgDocument(resourceCreator);
m_svg.LoadFromXml(resourceCreator, m_data_string);


But LoadFromXml crashes with that invalid parameter error. I see that the length of the data string is correct, but of course that is the number of characters, not the actual size of the data. Could there be a conflict between the UTF-8 attribute in the svg and the fact that it is now recorded as 16-bit characters? If so, how would one load an xml document from such data?



[Update] with the suggestion that I use winrt::to_hstring. I read the unsigned char data into a std::string,



std::string cstring = std::string("");
cstring.assign(data, data + dataLength);


Then I convert that:



m_data_string = winrt::to_hstring(cstring);


And finally try to load an svg as before:



m_svg.LoadFromXml(resourceCreator, m_data_string);


And it crashes as before. I notice that in the debugger that converted string in neither case appeared to be gibberish - in both cases it read in the debugger as the expected svg data. But if this hstring is wide chars wouldn't that be a conflict with the attribute in the svg that identifies it as UTF-8?



[Update] I'm starting to wonder if anyone has ever used CanvasSvgDocument.Draw() to draw an svg loaded from a file. The files are now loading without crashing without any change to their internal encoding reference. But - they won't draw. These files - 239 of them - are UTF-8, svg 1.1, and they display nicely if opened in Edge or any browser. But if I load the file data to an hstring, create a CanvasSvgDocument and then use CanvasSvgDocument.LoadFromXml to load them, they do not draw when called by CanvasSvgDocument's draw method. Other drawing of shapes, etc. works fine during the drawing session. Here is what could be a hint: If I call GetXML() on one of these svgs after it is loaded, what is returned is just this:



<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>


That is, the drawing information is not there. Or is this the full extent of what GetXml() is meant to return? That wouldn't seem useful. So perhaps CanvasSvgDocument.LoadFromXml(ResourceCreator, String) doesn't actually work yet?
So I'm back to asking again: is there a way to load a functional CanvasSvgDocument from file data?










share|improve this question

























  • std::wstring(data, data + dataLength) is wrong. It doesn't convert from UTF-8 to UTF-16; it merely widens the UTF-8 code units, producing gibberish. Use winrt::to_hstring instead.

    – IInspectable
    Nov 15 '18 at 21:46











  • Thanks, IInspectable - I can use to_hstring but still get the same crash. I'll update above to show what I mean.

    – user3743210
    Nov 15 '18 at 22:30











  • I experimented with a single svg file: manually changed "encoding=UTF-8" to read "encoding=UTF-16". That file will now load. If further work establishes that these files now can be used normally I'll post an answer, that an svg file cannot be loaded with CanvasSvgDocument.LoadFromXml() if it is internally identified as UTF-8. The svg can be correctly converted to a wide string, but that internal mention of UTF-8 will cause a conflict.

    – user3743210
    Nov 15 '18 at 23:49











  • How exactly does the code crash? Does it display a failed debug assertion dialog? Does it raise an exception? In the latter case, what's the callstack at the point of failure? Have you tried using LoadElementFromXml instead? Apparently, it doesn't require a complete XML document, so that may be a way for you to safely remove the encoding element from the SVG XML file(s) (unless I'm reading the documentation wrong).

    – IInspectable
    Nov 16 '18 at 10:08













  • Thanks - It was an invalid parameter error. Turned out to be the clash between the wide-character string and its internal reference to UTF-8. I'll answer the question and show what I did to fix it.

    – user3743210
    Nov 16 '18 at 19:36
















0















In a C++/winrt project I have a large number of small svg resources to be loaded from file. Since it would be slow to reload them all from disk at each CreateResources event from the CanvasVirtualControl I have loaded them in advance and stored the data for each in an array. When CreateResources happens my intent is to load a CanvasSvgDocument for each of these by using the CanvasSvgDocument method LoadFromXml(System.string). However, If I create an svgDocument using the resourcecreator, I get an invalid argument crash when calling LoadFromXml(). The resourceCreator argument looks right (VS preview 6 now allows me to see local variables!) and the xml data string argument looks like the valid svg data, so my best guess about the crash is that the data string is the wrong format. The file data is UTF-8. If I convert that to a std::wstring as I must for the LoadFromXml argument can it still be understood as byte data?
For example, I create the std::wstring this way, given a pointer to unsigned char file data and its length in bytes:



m_data_string = std::wstring(data, data + dataLength);


When CreateResources is triggered that datastring is referenced this way:



m_svg = CanvasSvgDocument(resourceCreator);
m_svg.LoadFromXml(resourceCreator, m_data_string);


But LoadFromXml crashes with that invalid parameter error. I see that the length of the data string is correct, but of course that is the number of characters, not the actual size of the data. Could there be a conflict between the UTF-8 attribute in the svg and the fact that it is now recorded as 16-bit characters? If so, how would one load an xml document from such data?



[Update] with the suggestion that I use winrt::to_hstring. I read the unsigned char data into a std::string,



std::string cstring = std::string("");
cstring.assign(data, data + dataLength);


Then I convert that:



m_data_string = winrt::to_hstring(cstring);


And finally try to load an svg as before:



m_svg.LoadFromXml(resourceCreator, m_data_string);


And it crashes as before. I notice that in the debugger that converted string in neither case appeared to be gibberish - in both cases it read in the debugger as the expected svg data. But if this hstring is wide chars wouldn't that be a conflict with the attribute in the svg that identifies it as UTF-8?



[Update] I'm starting to wonder if anyone has ever used CanvasSvgDocument.Draw() to draw an svg loaded from a file. The files are now loading without crashing without any change to their internal encoding reference. But - they won't draw. These files - 239 of them - are UTF-8, svg 1.1, and they display nicely if opened in Edge or any browser. But if I load the file data to an hstring, create a CanvasSvgDocument and then use CanvasSvgDocument.LoadFromXml to load them, they do not draw when called by CanvasSvgDocument's draw method. Other drawing of shapes, etc. works fine during the drawing session. Here is what could be a hint: If I call GetXML() on one of these svgs after it is loaded, what is returned is just this:



<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>


That is, the drawing information is not there. Or is this the full extent of what GetXml() is meant to return? That wouldn't seem useful. So perhaps CanvasSvgDocument.LoadFromXml(ResourceCreator, String) doesn't actually work yet?
So I'm back to asking again: is there a way to load a functional CanvasSvgDocument from file data?










share|improve this question

























  • std::wstring(data, data + dataLength) is wrong. It doesn't convert from UTF-8 to UTF-16; it merely widens the UTF-8 code units, producing gibberish. Use winrt::to_hstring instead.

    – IInspectable
    Nov 15 '18 at 21:46











  • Thanks, IInspectable - I can use to_hstring but still get the same crash. I'll update above to show what I mean.

    – user3743210
    Nov 15 '18 at 22:30











  • I experimented with a single svg file: manually changed "encoding=UTF-8" to read "encoding=UTF-16". That file will now load. If further work establishes that these files now can be used normally I'll post an answer, that an svg file cannot be loaded with CanvasSvgDocument.LoadFromXml() if it is internally identified as UTF-8. The svg can be correctly converted to a wide string, but that internal mention of UTF-8 will cause a conflict.

    – user3743210
    Nov 15 '18 at 23:49











  • How exactly does the code crash? Does it display a failed debug assertion dialog? Does it raise an exception? In the latter case, what's the callstack at the point of failure? Have you tried using LoadElementFromXml instead? Apparently, it doesn't require a complete XML document, so that may be a way for you to safely remove the encoding element from the SVG XML file(s) (unless I'm reading the documentation wrong).

    – IInspectable
    Nov 16 '18 at 10:08













  • Thanks - It was an invalid parameter error. Turned out to be the clash between the wide-character string and its internal reference to UTF-8. I'll answer the question and show what I did to fix it.

    – user3743210
    Nov 16 '18 at 19:36














0












0








0








In a C++/winrt project I have a large number of small svg resources to be loaded from file. Since it would be slow to reload them all from disk at each CreateResources event from the CanvasVirtualControl I have loaded them in advance and stored the data for each in an array. When CreateResources happens my intent is to load a CanvasSvgDocument for each of these by using the CanvasSvgDocument method LoadFromXml(System.string). However, If I create an svgDocument using the resourcecreator, I get an invalid argument crash when calling LoadFromXml(). The resourceCreator argument looks right (VS preview 6 now allows me to see local variables!) and the xml data string argument looks like the valid svg data, so my best guess about the crash is that the data string is the wrong format. The file data is UTF-8. If I convert that to a std::wstring as I must for the LoadFromXml argument can it still be understood as byte data?
For example, I create the std::wstring this way, given a pointer to unsigned char file data and its length in bytes:



m_data_string = std::wstring(data, data + dataLength);


When CreateResources is triggered that datastring is referenced this way:



m_svg = CanvasSvgDocument(resourceCreator);
m_svg.LoadFromXml(resourceCreator, m_data_string);


But LoadFromXml crashes with that invalid parameter error. I see that the length of the data string is correct, but of course that is the number of characters, not the actual size of the data. Could there be a conflict between the UTF-8 attribute in the svg and the fact that it is now recorded as 16-bit characters? If so, how would one load an xml document from such data?



[Update] with the suggestion that I use winrt::to_hstring. I read the unsigned char data into a std::string,



std::string cstring = std::string("");
cstring.assign(data, data + dataLength);


Then I convert that:



m_data_string = winrt::to_hstring(cstring);


And finally try to load an svg as before:



m_svg.LoadFromXml(resourceCreator, m_data_string);


And it crashes as before. I notice that in the debugger that converted string in neither case appeared to be gibberish - in both cases it read in the debugger as the expected svg data. But if this hstring is wide chars wouldn't that be a conflict with the attribute in the svg that identifies it as UTF-8?



[Update] I'm starting to wonder if anyone has ever used CanvasSvgDocument.Draw() to draw an svg loaded from a file. The files are now loading without crashing without any change to their internal encoding reference. But - they won't draw. These files - 239 of them - are UTF-8, svg 1.1, and they display nicely if opened in Edge or any browser. But if I load the file data to an hstring, create a CanvasSvgDocument and then use CanvasSvgDocument.LoadFromXml to load them, they do not draw when called by CanvasSvgDocument's draw method. Other drawing of shapes, etc. works fine during the drawing session. Here is what could be a hint: If I call GetXML() on one of these svgs after it is loaded, what is returned is just this:



<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>


That is, the drawing information is not there. Or is this the full extent of what GetXml() is meant to return? That wouldn't seem useful. So perhaps CanvasSvgDocument.LoadFromXml(ResourceCreator, String) doesn't actually work yet?
So I'm back to asking again: is there a way to load a functional CanvasSvgDocument from file data?










share|improve this question
















In a C++/winrt project I have a large number of small svg resources to be loaded from file. Since it would be slow to reload them all from disk at each CreateResources event from the CanvasVirtualControl I have loaded them in advance and stored the data for each in an array. When CreateResources happens my intent is to load a CanvasSvgDocument for each of these by using the CanvasSvgDocument method LoadFromXml(System.string). However, If I create an svgDocument using the resourcecreator, I get an invalid argument crash when calling LoadFromXml(). The resourceCreator argument looks right (VS preview 6 now allows me to see local variables!) and the xml data string argument looks like the valid svg data, so my best guess about the crash is that the data string is the wrong format. The file data is UTF-8. If I convert that to a std::wstring as I must for the LoadFromXml argument can it still be understood as byte data?
For example, I create the std::wstring this way, given a pointer to unsigned char file data and its length in bytes:



m_data_string = std::wstring(data, data + dataLength);


When CreateResources is triggered that datastring is referenced this way:



m_svg = CanvasSvgDocument(resourceCreator);
m_svg.LoadFromXml(resourceCreator, m_data_string);


But LoadFromXml crashes with that invalid parameter error. I see that the length of the data string is correct, but of course that is the number of characters, not the actual size of the data. Could there be a conflict between the UTF-8 attribute in the svg and the fact that it is now recorded as 16-bit characters? If so, how would one load an xml document from such data?



[Update] with the suggestion that I use winrt::to_hstring. I read the unsigned char data into a std::string,



std::string cstring = std::string("");
cstring.assign(data, data + dataLength);


Then I convert that:



m_data_string = winrt::to_hstring(cstring);


And finally try to load an svg as before:



m_svg.LoadFromXml(resourceCreator, m_data_string);


And it crashes as before. I notice that in the debugger that converted string in neither case appeared to be gibberish - in both cases it read in the debugger as the expected svg data. But if this hstring is wide chars wouldn't that be a conflict with the attribute in the svg that identifies it as UTF-8?



[Update] I'm starting to wonder if anyone has ever used CanvasSvgDocument.Draw() to draw an svg loaded from a file. The files are now loading without crashing without any change to their internal encoding reference. But - they won't draw. These files - 239 of them - are UTF-8, svg 1.1, and they display nicely if opened in Edge or any browser. But if I load the file data to an hstring, create a CanvasSvgDocument and then use CanvasSvgDocument.LoadFromXml to load them, they do not draw when called by CanvasSvgDocument's draw method. Other drawing of shapes, etc. works fine during the drawing session. Here is what could be a hint: If I call GetXML() on one of these svgs after it is loaded, what is returned is just this:



<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>


That is, the drawing information is not there. Or is this the full extent of what GetXml() is meant to return? That wouldn't seem useful. So perhaps CanvasSvgDocument.LoadFromXml(ResourceCreator, String) doesn't actually work yet?
So I'm back to asking again: is there a way to load a functional CanvasSvgDocument from file data?







c++-winrt win2d






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 20:18







user3743210

















asked Nov 15 '18 at 21:14









user3743210user3743210

3917




3917













  • std::wstring(data, data + dataLength) is wrong. It doesn't convert from UTF-8 to UTF-16; it merely widens the UTF-8 code units, producing gibberish. Use winrt::to_hstring instead.

    – IInspectable
    Nov 15 '18 at 21:46











  • Thanks, IInspectable - I can use to_hstring but still get the same crash. I'll update above to show what I mean.

    – user3743210
    Nov 15 '18 at 22:30











  • I experimented with a single svg file: manually changed "encoding=UTF-8" to read "encoding=UTF-16". That file will now load. If further work establishes that these files now can be used normally I'll post an answer, that an svg file cannot be loaded with CanvasSvgDocument.LoadFromXml() if it is internally identified as UTF-8. The svg can be correctly converted to a wide string, but that internal mention of UTF-8 will cause a conflict.

    – user3743210
    Nov 15 '18 at 23:49











  • How exactly does the code crash? Does it display a failed debug assertion dialog? Does it raise an exception? In the latter case, what's the callstack at the point of failure? Have you tried using LoadElementFromXml instead? Apparently, it doesn't require a complete XML document, so that may be a way for you to safely remove the encoding element from the SVG XML file(s) (unless I'm reading the documentation wrong).

    – IInspectable
    Nov 16 '18 at 10:08













  • Thanks - It was an invalid parameter error. Turned out to be the clash between the wide-character string and its internal reference to UTF-8. I'll answer the question and show what I did to fix it.

    – user3743210
    Nov 16 '18 at 19:36



















  • std::wstring(data, data + dataLength) is wrong. It doesn't convert from UTF-8 to UTF-16; it merely widens the UTF-8 code units, producing gibberish. Use winrt::to_hstring instead.

    – IInspectable
    Nov 15 '18 at 21:46











  • Thanks, IInspectable - I can use to_hstring but still get the same crash. I'll update above to show what I mean.

    – user3743210
    Nov 15 '18 at 22:30











  • I experimented with a single svg file: manually changed "encoding=UTF-8" to read "encoding=UTF-16". That file will now load. If further work establishes that these files now can be used normally I'll post an answer, that an svg file cannot be loaded with CanvasSvgDocument.LoadFromXml() if it is internally identified as UTF-8. The svg can be correctly converted to a wide string, but that internal mention of UTF-8 will cause a conflict.

    – user3743210
    Nov 15 '18 at 23:49











  • How exactly does the code crash? Does it display a failed debug assertion dialog? Does it raise an exception? In the latter case, what's the callstack at the point of failure? Have you tried using LoadElementFromXml instead? Apparently, it doesn't require a complete XML document, so that may be a way for you to safely remove the encoding element from the SVG XML file(s) (unless I'm reading the documentation wrong).

    – IInspectable
    Nov 16 '18 at 10:08













  • Thanks - It was an invalid parameter error. Turned out to be the clash between the wide-character string and its internal reference to UTF-8. I'll answer the question and show what I did to fix it.

    – user3743210
    Nov 16 '18 at 19:36

















std::wstring(data, data + dataLength) is wrong. It doesn't convert from UTF-8 to UTF-16; it merely widens the UTF-8 code units, producing gibberish. Use winrt::to_hstring instead.

– IInspectable
Nov 15 '18 at 21:46





std::wstring(data, data + dataLength) is wrong. It doesn't convert from UTF-8 to UTF-16; it merely widens the UTF-8 code units, producing gibberish. Use winrt::to_hstring instead.

– IInspectable
Nov 15 '18 at 21:46













Thanks, IInspectable - I can use to_hstring but still get the same crash. I'll update above to show what I mean.

– user3743210
Nov 15 '18 at 22:30





Thanks, IInspectable - I can use to_hstring but still get the same crash. I'll update above to show what I mean.

– user3743210
Nov 15 '18 at 22:30













I experimented with a single svg file: manually changed "encoding=UTF-8" to read "encoding=UTF-16". That file will now load. If further work establishes that these files now can be used normally I'll post an answer, that an svg file cannot be loaded with CanvasSvgDocument.LoadFromXml() if it is internally identified as UTF-8. The svg can be correctly converted to a wide string, but that internal mention of UTF-8 will cause a conflict.

– user3743210
Nov 15 '18 at 23:49





I experimented with a single svg file: manually changed "encoding=UTF-8" to read "encoding=UTF-16". That file will now load. If further work establishes that these files now can be used normally I'll post an answer, that an svg file cannot be loaded with CanvasSvgDocument.LoadFromXml() if it is internally identified as UTF-8. The svg can be correctly converted to a wide string, but that internal mention of UTF-8 will cause a conflict.

– user3743210
Nov 15 '18 at 23:49













How exactly does the code crash? Does it display a failed debug assertion dialog? Does it raise an exception? In the latter case, what's the callstack at the point of failure? Have you tried using LoadElementFromXml instead? Apparently, it doesn't require a complete XML document, so that may be a way for you to safely remove the encoding element from the SVG XML file(s) (unless I'm reading the documentation wrong).

– IInspectable
Nov 16 '18 at 10:08







How exactly does the code crash? Does it display a failed debug assertion dialog? Does it raise an exception? In the latter case, what's the callstack at the point of failure? Have you tried using LoadElementFromXml instead? Apparently, it doesn't require a complete XML document, so that may be a way for you to safely remove the encoding element from the SVG XML file(s) (unless I'm reading the documentation wrong).

– IInspectable
Nov 16 '18 at 10:08















Thanks - It was an invalid parameter error. Turned out to be the clash between the wide-character string and its internal reference to UTF-8. I'll answer the question and show what I did to fix it.

– user3743210
Nov 16 '18 at 19:36





Thanks - It was an invalid parameter error. Turned out to be the clash between the wide-character string and its internal reference to UTF-8. I'll answer the question and show what I did to fix it.

– user3743210
Nov 16 '18 at 19:36












1 Answer
1






active

oldest

votes


















0














My first answer here was wrong: the fault in my code above is that LoadFromXml() is a static method, and someone pointed out to me elsewhere, I was discarding the returned result. It should be theSvg = CanvasSvgDocument::LoadFromXml(string).
Having corrected that, I'm back to the problem of loading UTF-8 data in a method whose argument is a wide-character string. Changing the internal reference to UTF-16 doesn't help after all. Loading the svg with CanvasSvgDocument::LoadAsync(filestream) works, but if I want to load these without re-accessing the disk I will need to find a way to make RandomAccessFileStream from a buffer of bytes and then use LoadAsync. I think. Unless there is some other way to make LoadFromXmL() work - at present it fails with an invalid argument error.






share|improve this answer


























  • Appears that while this solved the loading problem, the resulting svg will not draw. I tried opening the svg in a text editor and saving it as little-endian 16-bit text, marking it as UTF-16LE, but that will not load. There may not be a way to use an 8-bit svg from file data using LoadFromXML. Loading them directly from file with LoadAsync works, at the cost of reading hundreds of them from disk at each CreateResources. If I find a better solution I'll expand my answer above. Or maybe some else will...

    – user3743210
    Nov 16 '18 at 22:22











  • I was mistaken, it appears - I can now load svgs from the 8-bit files without changing their internal encoding reference to UTF-16. But they will not draw using CanvasSvgDocument->Draw. I'll add more to my question above. Might need to post a new question.

    – user3743210
    Nov 18 '18 at 19:35











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327975%2fhow-to-load-canvassvgdocument-from-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














My first answer here was wrong: the fault in my code above is that LoadFromXml() is a static method, and someone pointed out to me elsewhere, I was discarding the returned result. It should be theSvg = CanvasSvgDocument::LoadFromXml(string).
Having corrected that, I'm back to the problem of loading UTF-8 data in a method whose argument is a wide-character string. Changing the internal reference to UTF-16 doesn't help after all. Loading the svg with CanvasSvgDocument::LoadAsync(filestream) works, but if I want to load these without re-accessing the disk I will need to find a way to make RandomAccessFileStream from a buffer of bytes and then use LoadAsync. I think. Unless there is some other way to make LoadFromXmL() work - at present it fails with an invalid argument error.






share|improve this answer


























  • Appears that while this solved the loading problem, the resulting svg will not draw. I tried opening the svg in a text editor and saving it as little-endian 16-bit text, marking it as UTF-16LE, but that will not load. There may not be a way to use an 8-bit svg from file data using LoadFromXML. Loading them directly from file with LoadAsync works, at the cost of reading hundreds of them from disk at each CreateResources. If I find a better solution I'll expand my answer above. Or maybe some else will...

    – user3743210
    Nov 16 '18 at 22:22











  • I was mistaken, it appears - I can now load svgs from the 8-bit files without changing their internal encoding reference to UTF-16. But they will not draw using CanvasSvgDocument->Draw. I'll add more to my question above. Might need to post a new question.

    – user3743210
    Nov 18 '18 at 19:35
















0














My first answer here was wrong: the fault in my code above is that LoadFromXml() is a static method, and someone pointed out to me elsewhere, I was discarding the returned result. It should be theSvg = CanvasSvgDocument::LoadFromXml(string).
Having corrected that, I'm back to the problem of loading UTF-8 data in a method whose argument is a wide-character string. Changing the internal reference to UTF-16 doesn't help after all. Loading the svg with CanvasSvgDocument::LoadAsync(filestream) works, but if I want to load these without re-accessing the disk I will need to find a way to make RandomAccessFileStream from a buffer of bytes and then use LoadAsync. I think. Unless there is some other way to make LoadFromXmL() work - at present it fails with an invalid argument error.






share|improve this answer


























  • Appears that while this solved the loading problem, the resulting svg will not draw. I tried opening the svg in a text editor and saving it as little-endian 16-bit text, marking it as UTF-16LE, but that will not load. There may not be a way to use an 8-bit svg from file data using LoadFromXML. Loading them directly from file with LoadAsync works, at the cost of reading hundreds of them from disk at each CreateResources. If I find a better solution I'll expand my answer above. Or maybe some else will...

    – user3743210
    Nov 16 '18 at 22:22











  • I was mistaken, it appears - I can now load svgs from the 8-bit files without changing their internal encoding reference to UTF-16. But they will not draw using CanvasSvgDocument->Draw. I'll add more to my question above. Might need to post a new question.

    – user3743210
    Nov 18 '18 at 19:35














0












0








0







My first answer here was wrong: the fault in my code above is that LoadFromXml() is a static method, and someone pointed out to me elsewhere, I was discarding the returned result. It should be theSvg = CanvasSvgDocument::LoadFromXml(string).
Having corrected that, I'm back to the problem of loading UTF-8 data in a method whose argument is a wide-character string. Changing the internal reference to UTF-16 doesn't help after all. Loading the svg with CanvasSvgDocument::LoadAsync(filestream) works, but if I want to load these without re-accessing the disk I will need to find a way to make RandomAccessFileStream from a buffer of bytes and then use LoadAsync. I think. Unless there is some other way to make LoadFromXmL() work - at present it fails with an invalid argument error.






share|improve this answer















My first answer here was wrong: the fault in my code above is that LoadFromXml() is a static method, and someone pointed out to me elsewhere, I was discarding the returned result. It should be theSvg = CanvasSvgDocument::LoadFromXml(string).
Having corrected that, I'm back to the problem of loading UTF-8 data in a method whose argument is a wide-character string. Changing the internal reference to UTF-16 doesn't help after all. Loading the svg with CanvasSvgDocument::LoadAsync(filestream) works, but if I want to load these without re-accessing the disk I will need to find a way to make RandomAccessFileStream from a buffer of bytes and then use LoadAsync. I think. Unless there is some other way to make LoadFromXmL() work - at present it fails with an invalid argument error.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 5:46

























answered Nov 16 '18 at 19:59









user3743210user3743210

3917




3917













  • Appears that while this solved the loading problem, the resulting svg will not draw. I tried opening the svg in a text editor and saving it as little-endian 16-bit text, marking it as UTF-16LE, but that will not load. There may not be a way to use an 8-bit svg from file data using LoadFromXML. Loading them directly from file with LoadAsync works, at the cost of reading hundreds of them from disk at each CreateResources. If I find a better solution I'll expand my answer above. Or maybe some else will...

    – user3743210
    Nov 16 '18 at 22:22











  • I was mistaken, it appears - I can now load svgs from the 8-bit files without changing their internal encoding reference to UTF-16. But they will not draw using CanvasSvgDocument->Draw. I'll add more to my question above. Might need to post a new question.

    – user3743210
    Nov 18 '18 at 19:35



















  • Appears that while this solved the loading problem, the resulting svg will not draw. I tried opening the svg in a text editor and saving it as little-endian 16-bit text, marking it as UTF-16LE, but that will not load. There may not be a way to use an 8-bit svg from file data using LoadFromXML. Loading them directly from file with LoadAsync works, at the cost of reading hundreds of them from disk at each CreateResources. If I find a better solution I'll expand my answer above. Or maybe some else will...

    – user3743210
    Nov 16 '18 at 22:22











  • I was mistaken, it appears - I can now load svgs from the 8-bit files without changing their internal encoding reference to UTF-16. But they will not draw using CanvasSvgDocument->Draw. I'll add more to my question above. Might need to post a new question.

    – user3743210
    Nov 18 '18 at 19:35

















Appears that while this solved the loading problem, the resulting svg will not draw. I tried opening the svg in a text editor and saving it as little-endian 16-bit text, marking it as UTF-16LE, but that will not load. There may not be a way to use an 8-bit svg from file data using LoadFromXML. Loading them directly from file with LoadAsync works, at the cost of reading hundreds of them from disk at each CreateResources. If I find a better solution I'll expand my answer above. Or maybe some else will...

– user3743210
Nov 16 '18 at 22:22





Appears that while this solved the loading problem, the resulting svg will not draw. I tried opening the svg in a text editor and saving it as little-endian 16-bit text, marking it as UTF-16LE, but that will not load. There may not be a way to use an 8-bit svg from file data using LoadFromXML. Loading them directly from file with LoadAsync works, at the cost of reading hundreds of them from disk at each CreateResources. If I find a better solution I'll expand my answer above. Or maybe some else will...

– user3743210
Nov 16 '18 at 22:22













I was mistaken, it appears - I can now load svgs from the 8-bit files without changing their internal encoding reference to UTF-16. But they will not draw using CanvasSvgDocument->Draw. I'll add more to my question above. Might need to post a new question.

– user3743210
Nov 18 '18 at 19:35





I was mistaken, it appears - I can now load svgs from the 8-bit files without changing their internal encoding reference to UTF-16. But they will not draw using CanvasSvgDocument->Draw. I'll add more to my question above. Might need to post a new question.

– user3743210
Nov 18 '18 at 19:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327975%2fhow-to-load-canvassvgdocument-from-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."