fix: also calculate scaled amount regarding height

This commit is contained in:
KyleUltimate 2025-04-27 08:07:03 +08:00
parent 7b2ba0eb8c
commit 262b2af3e7
2 changed files with 11 additions and 1 deletions

View File

@ -176,6 +176,10 @@ impl ExportRenderer {
OutputFormat::Pdf => format!("{width}px"),
OutputFormat::Html => "100vw".to_string(),
};
let css_container_height = match self.output_format {
OutputFormat::Pdf => format!("{height}px"),
OutputFormat::Html => "100vh".to_string(),
};
let css = format!(
r"
pre {{
@ -192,6 +196,7 @@ impl ExportRenderer {
font-size: {FONT_SIZE}px;
line-height: {LINE_HEIGHT}px;
width: {css_container_width};
height: {css_container_height};
overflow: hidden;
transform-origin: top center;
background-color: {background_color};
@ -199,6 +204,7 @@ impl ExportRenderer {
.container {{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
@ -228,6 +234,7 @@ impl ExportRenderer {
"
<script>
let originalWidth = {width};
let originalHeight = {height};
{script}
</script>"
)

View File

@ -15,7 +15,10 @@ document.addEventListener('DOMContentLoaded', function() {
function scaler() {
var w = document.documentElement.clientWidth;
let scaledAmount= w/originalWidth;
var h = document.documentElement.clientHeight;
let widthScaledAmount= w/originalWidth;
let heightScaledAmount= h/originalHeight;
let scaledAmount = Math.min(widthScaledAmount, heightScaledAmount);
document.querySelector("body").style.transform = `scale(${scaledAmount})`;
}