@@ -2113,6 +2113,13 @@ static Color GetColorAttribute(const DOMNode* node, const char* name, PAGXDocume
21132113// Public API implementation
21142114// ==============================================================================
21152115
2116+ static void ResolveRelativePath (const std::string& basePath, std::string& path) {
2117+ if (path.empty () || path[0 ] == ' /' || path.find (" ://" ) != std::string::npos) {
2118+ return ;
2119+ }
2120+ path = basePath + path;
2121+ }
2122+
21162123std::shared_ptr<PAGXDocument> PAGXImporter::FromFile (const std::string& filePath) {
21172124 std::ifstream file (filePath, std::ios::binary | std::ios::ate);
21182125 if (!file) {
@@ -2141,17 +2148,11 @@ std::shared_ptr<PAGXDocument> PAGXImporter::FromFile(const std::string& filePath
21412148 for (auto & node : doc->nodes ) {
21422149 if (node->nodeType () == NodeType::Image) {
21432150 auto * image = static_cast <Image*>(node.get ());
2144- if (!image->filePath .empty () && image->filePath [0 ] != ' /' &&
2145- image->filePath .find (" ://" ) == std::string::npos) {
2146- image->filePath = basePath + image->filePath ;
2147- }
2151+ ResolveRelativePath (basePath, image->filePath );
21482152 }
21492153 if (node->nodeType () == NodeType::Font) {
21502154 auto * font = static_cast <Font*>(node.get ());
2151- if (!font->file .empty () && font->file [0 ] != ' /' &&
2152- font->file .find (" ://" ) == std::string::npos) {
2153- font->file = basePath + font->file ;
2154- }
2155+ ResolveRelativePath (basePath, font->file );
21552156 }
21562157 }
21572158 }
0 commit comments