| 51 | } |
| 52 | |
| 53 | std::shared_ptr<Image> LoadImage(const SVGIRI& href) { |
| 54 | |
| 55 | // SVG image URLs support five protocols: http://, https://, file://, path, and base64 |
| 56 | // For http, https, file, and path protocols: |
| 57 | // - http, https, and file require a registered StreamFactory |
| 58 | // - path protocol requires an absolute path |
| 59 | // - all are loaded using Image::MakeFromFile |
| 60 | // For base64 protocol: |
| 61 | // - base64 data is decoded and loaded using Image::MakeFromEncoded |
| 62 | |
| 63 | switch (href.type()) { |
| 64 | case SVGIRI::Type::DataURI: { |
| 65 | const auto& base64URL = href.iri(); |
| 66 | auto pos = base64URL.find("base64,"); |
| 67 | if (pos == std::string::npos) { |
| 68 | return Image::MakeFromFile(base64URL); |
| 69 | } |
| 70 | std::string base64Data = base64URL.substr(pos + 7); |
| 71 | auto data = Base64Decode(base64Data); |
| 72 | return data ? Image::MakeFromEncoded(data) : nullptr; |
| 73 | } |
| 74 | case SVGIRI::Type::Nonlocal: { |
| 75 | return Image::MakeFromFile(href.iri()); |
| 76 | } |
| 77 | default: |
| 78 | return nullptr; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | SVGImage::ImageInfo SVGImage::LoadImage(const SVGIRI& iri, const Rect& viewPort) { |
| 83 | std::shared_ptr<Image> image = ::tgfx::LoadImage(iri); |
no test coverage detected