Skip to content

Commit

Permalink
Merge pull request #1415 from ONLYOFFICE/fix/WmfSize
Browse files Browse the repository at this point in the history
Fix Wmf file Size
  • Loading branch information
K0R0L authored Feb 9, 2024
2 parents ba79959 + 581e546 commit 5ccef7b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DesktopEditor/raster/Metafile/Common/MetaFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace MetaFile
virtual bool IsWindowFlippedY() = 0;
virtual bool IsWindowFlippedX() = 0;
virtual unsigned int GetMapMode() = 0;
virtual double GetDpi() = 0;
virtual USHORT GetDpi() = 0;
virtual IRegion* GetRegion() = 0;
virtual unsigned int GetArcDirection() = 0;
virtual CPath* GetPath() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ namespace MetaFile
return m_pDC->GetMapMode();
}

double CEmfParserBase::GetDpi()
USHORT CEmfParserBase::GetDpi()
{
return 96.;
return 96;
}

IRegion *CEmfParserBase::GetRegion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace MetaFile
bool IsWindowFlippedY() override;
bool IsWindowFlippedX() override;
unsigned int GetMapMode() override;
double GetDpi() override;
USHORT GetDpi() override;
IRegion* GetRegion() override;
unsigned int GetArcDirection() override;
CPath* GetPath() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ namespace MetaFile
this->ClearFile();
}

double CEmfPlusParser::GetDpi()
USHORT CEmfPlusParser::GetDpi()
{
return (double)m_unLogicalDpiX;
return m_unLogicalDpiX;
}

EmfParserType CEmfPlusParser::GetType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace MetaFile

void PlayFile() override;
void Scan() override;
double GetDpi() override;
USHORT GetDpi() override;

EmfParserType GetType() override;

Expand Down
4 changes: 2 additions & 2 deletions DesktopEditor/raster/Metafile/StarView/SvmFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ class CSvmFile : virtual public IMetaFileBase
return MM_ANISOTROPIC;
}

double GetDpi()
USHORT GetDpi()
{
return 96.;
return 96;
}

IRegion* GetRegion()
Expand Down
28 changes: 15 additions & 13 deletions DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ namespace MetaFile
return m_pDC->GetMapMode();
}

double CWmfParserBase::GetDpi()
USHORT CWmfParserBase::GetDpi()
{
return (0 != m_oPlaceable.ushInch) ? m_oPlaceable.ushInch : 96.;
return (0 != m_oPlaceable.ushInch) ? m_oPlaceable.ushInch : 96;
}

IRegion *CWmfParserBase::GetRegion()
Expand Down Expand Up @@ -249,6 +249,19 @@ namespace MetaFile

oBB = m_oPlaceable.oBoundingBox;

const USHORT ushFileDpi = GetDpi();
const USHORT ushRendererDpi = 96;

if (ushFileDpi != ushRendererDpi && 0 != ushFileDpi)
{
const double dKoef = (double)ushRendererDpi / (double)ushFileDpi;

oBB.Left = std::round(oBB.Left * dKoef);
oBB.Top = std::round(oBB.Top * dKoef);
oBB.Right = std::round(oBB.Right * dKoef);
oBB.Bottom = std::round(oBB.Bottom * dKoef);
}

// Иногда m_oPlaceable.BoundingBox задается нулевой ширины и высоты
if (abs(oBB.Right - oBB.Left) <= 1)
{
Expand All @@ -261,17 +274,6 @@ namespace MetaFile
oBB.Bottom = m_oBoundingBox.Bottom;
}

const double dFileDpi = GetDpi();
const double dRendererDpi = 96;

if (Equals(dFileDpi, dRendererDpi) && !Equals(0, dFileDpi))
return oBB;

oBB.Left = std::round(oBB.Left * dRendererDpi / dFileDpi);
oBB.Top = std::round(oBB.Top * dRendererDpi / dFileDpi);
oBB.Right = std::round(oBB.Right * dRendererDpi / dFileDpi);
oBB.Bottom = std::round(oBB.Bottom * dRendererDpi / dFileDpi);

return oBB;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace MetaFile
bool IsWindowFlippedY() override;
bool IsWindowFlippedX() override;
unsigned int GetMapMode() override;
double GetDpi() override;
USHORT GetDpi() override;
IRegion* GetRegion() override;
unsigned int GetArcDirection() override;
CPath* GetPath() override;
Expand Down

0 comments on commit 5ccef7b

Please sign in to comment.