Loading editor/widgets/image/image.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,22 @@ extern "C" { if (realWidth > 0 && realHeight > 0) { img.setAttribute("width", std::to_string(realWidth).c_str()); img.setAttribute("height", std::to_string(realHeight).c_str()); } else { // Fallback: set width/height from CSS values if they are pixel values auto extractPx = [](const std::string &val) -> int { if (val.empty() || val == "auto") return 0; std::string v = val; if (v.size() > 2 && v.substr(v.size()-2) == "px") v = v.substr(0, v.size()-2); else if (v.find('%') != std::string::npos || v.find("em") != std::string::npos || v.find("vw") != std::string::npos || v.find("vh") != std::string::npos) return 0; try { return static_cast<int>(std::stod(v) + 0.5); } catch(...) { return 0; } }; int pw = extractPx(width); int ph = extractPx(height); if (pw > 0) img.setAttribute("width", std::to_string(pw).c_str()); if (ph > 0) img.setAttribute("height", std::to_string(ph).c_str()); } // Compute effective width/height, auto-calculating from aspect ratio Loading Loading @@ -544,6 +560,9 @@ extern "C" { std::string style; style += "width: " + effWidth + ";"; style += " height: " + effHeight + ";"; if (realWidth > 0 && realHeight > 0) { style += " aspect-ratio: " + std::to_string(realWidth) + " / " + std::to_string(realHeight) + ";"; } style += " object-fit: " + objectFit + ";"; if (borderRadius != "0") { style += " border-radius: " + borderRadius + ";"; Loading Loading
editor/widgets/image/image.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -490,6 +490,22 @@ extern "C" { if (realWidth > 0 && realHeight > 0) { img.setAttribute("width", std::to_string(realWidth).c_str()); img.setAttribute("height", std::to_string(realHeight).c_str()); } else { // Fallback: set width/height from CSS values if they are pixel values auto extractPx = [](const std::string &val) -> int { if (val.empty() || val == "auto") return 0; std::string v = val; if (v.size() > 2 && v.substr(v.size()-2) == "px") v = v.substr(0, v.size()-2); else if (v.find('%') != std::string::npos || v.find("em") != std::string::npos || v.find("vw") != std::string::npos || v.find("vh") != std::string::npos) return 0; try { return static_cast<int>(std::stod(v) + 0.5); } catch(...) { return 0; } }; int pw = extractPx(width); int ph = extractPx(height); if (pw > 0) img.setAttribute("width", std::to_string(pw).c_str()); if (ph > 0) img.setAttribute("height", std::to_string(ph).c_str()); } // Compute effective width/height, auto-calculating from aspect ratio Loading Loading @@ -544,6 +560,9 @@ extern "C" { std::string style; style += "width: " + effWidth + ";"; style += " height: " + effHeight + ";"; if (realWidth > 0 && realHeight > 0) { style += " aspect-ratio: " + std::to_string(realWidth) + " / " + std::to_string(realHeight) + ";"; } style += " object-fit: " + objectFit + ";"; if (borderRadius != "0") { style += " border-radius: " + borderRadius + ";"; Loading