Adding flag support for marker and refactoring in svg-reader

This commit is contained in:
Kirill Poljakov
2023-05-22 13:52:58 +03:00
parent cbed11f00b
commit 96662a2382
7 changed files with 31 additions and 26 deletions

View File

@ -255,7 +255,7 @@ namespace NSCSS
bool CDigit::Zero() const
{
return DBL_MIN == m_oValue || 0. == m_oValue;
return 0. == m_oValue;
}
void CDigit::Clear()

View File

@ -111,9 +111,9 @@ bool CSvgFile::Draw(IRenderer *pRenderer, double dX, double dY, double dWidth, d
SVG::TRect oWindow = m_pContainer->GetWindow();
SVG::TRect oViewBox = m_pContainer->GetViewBox();
if (oWindow.m_oWidth.Zero())
if (oWindow.m_oWidth.Empty() || oWindow.m_oWidth.Zero())
{
if (oViewBox.m_oWidth.Zero())
if (oViewBox.m_oWidth.Empty() || oViewBox.m_oWidth.Zero())
oWindow.m_oWidth = 300;
else
{
@ -122,9 +122,9 @@ bool CSvgFile::Draw(IRenderer *pRenderer, double dX, double dY, double dWidth, d
}
}
if (oWindow.m_oHeight.Zero())
if (oWindow.m_oHeight.Empty() || oWindow.m_oHeight.Zero())
{
if (oViewBox.m_oHeight.Zero())
if (oViewBox.m_oHeight.Empty() || oViewBox.m_oHeight.Zero())
oWindow.m_oHeight = 150;
else
{
@ -149,18 +149,18 @@ bool CSvgFile::Draw(IRenderer *pRenderer, double dX, double dY, double dWidth, d
double dM11 = 1;
double dM22 = 1;
if (!oWindow.m_oWidth.Zero())
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero())
dM11 = dWidth / dWindowWidth;
if (!oWindow.m_oHeight.Zero())
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero())
dM22 = dHeight / dWindowHeight;
double dScaleX = 1, dScaleY = 1;
if (!oWindow.m_oWidth.Zero() && !oViewBox.m_oWidth.Zero())
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero() && !oViewBox.m_oWidth.Empty() && !oViewBox.m_oWidth.Zero())
dScaleX = dWindowWidth / dViewBoxWidth;
if (!oWindow.m_oHeight.Zero() && !oViewBox.m_oHeight.Zero())
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero() && !oViewBox.m_oHeight.Empty() && !oViewBox.m_oHeight.Zero())
dScaleY = dWindowHeight / dViewBoxHeight;
double dSkipX = -oViewBox.m_oX.ToDouble(NSCSS::Pixel) * dScaleX * dM11;

View File

@ -40,10 +40,10 @@ namespace SVG
const std::wstring& wsUnits = oNode.GetAttribute(L"markerUnits");
if (L"strokeWidth" == wsUnits)
m_enUnits = Marker_StrokeWidth;
else if (L"userSpaceOnUse" == wsUnits)
if (L"userSpaceOnUse" == wsUnits)
m_enUnits = Marker_UserSpaceOnUse;
else
m_enUnits = Marker_StrokeWidth;
}
CMarker::~CMarker()
@ -122,11 +122,11 @@ namespace SVG
void CMarker::Draw(IRenderer *pRenderer, const std::vector<Point> &arPoints, double dStrokeWidth) const
{
if (NULL == m_pImage || arPoints.empty())
if (NULL == m_pImage || arPoints.empty() || 0. == dStrokeWidth)
return;
double dWidth = m_oWindow.m_oWidth.ToDouble(NSCSS::Pixel);
double dHeight = m_oWindow.m_oHeight.ToDouble(NSCSS::Pixel);
double dWidth = m_oWindow.m_oWidth.ToDouble(NSCSS::Pixel) * ((Marker_StrokeWidth == m_enUnits) ? dStrokeWidth : 1.);
double dHeight = m_oWindow.m_oHeight.ToDouble(NSCSS::Pixel) * ((Marker_StrokeWidth == m_enUnits) ? dStrokeWidth : 1.);
double dVBWidth = m_oViewBox.m_oWidth.ToDouble(NSCSS::Pixel);
double dVBHeight = m_oViewBox.m_oHeight.ToDouble(NSCSS::Pixel);

View File

@ -113,7 +113,7 @@ namespace SVG
bool CSvgGraphicsObject::Apply(IRenderer *pRenderer, const TStroke *pStroke, bool bUseDefault) const
{
if (NULL == pRenderer || NULL == pStroke || NSCSS::NSProperties::ColorType::ColorNone == pStroke->m_oColor.GetType() || (!bUseDefault && (pStroke->m_oWidth.Zero() && pStroke->m_oColor.Empty())))
if (NULL == pRenderer || NULL == pStroke || NSCSS::NSProperties::ColorType::ColorNone == pStroke->m_oColor.GetType() || (!bUseDefault && ((pStroke->m_oWidth.Empty() || pStroke->m_oWidth.Zero()) && pStroke->m_oColor.Empty())))
{
pRenderer->put_PenSize(0);
return false;

View File

@ -73,9 +73,11 @@ namespace SVG
bool CPath::DrawMarkers(IRenderer *pRenderer, const CDefs *pDefs) const
{
if (NULL == pRenderer || NULL == pDefs || m_arElements.empty())
if (NULL == pRenderer || NULL == pDefs || m_arElements.empty() || m_oStyles.m_oStroke.m_oWidth.Zero())
return false;
double dStrokeWidth = (m_oStyles.m_oStroke.m_oWidth.Empty()) ? 1. : m_oStyles.m_oStroke.m_oWidth.ToDouble(NSCSS::Pixel);
std::vector<Point> arPoints(m_arElements.size());
for (unsigned int unIndex = 0; unIndex < m_arElements.size(); ++unIndex)
@ -88,7 +90,7 @@ namespace SVG
if (NULL != pStartMarker)
{
pStartMarker->Update(pDefs);
pStartMarker->Draw(pRenderer, {*arPoints.begin()}, m_oStyles.m_oStroke.m_oWidth.ToDouble(NSCSS::Pixel));
pStartMarker->Draw(pRenderer, {*arPoints.begin()}, dStrokeWidth);
}
}
@ -99,7 +101,7 @@ namespace SVG
if (NULL != pMidMarker)
{
pMidMarker->Update(pDefs);
pMidMarker->Draw(pRenderer, std::vector<Point>(arPoints.begin() + 1, arPoints.end() - 1), m_oStyles.m_oStroke.m_oWidth.ToDouble(NSCSS::Pixel));
pMidMarker->Draw(pRenderer, std::vector<Point>(arPoints.begin() + 1, arPoints.end() - 1), dStrokeWidth);
}
}
@ -110,7 +112,7 @@ namespace SVG
if (NULL != pEndMarker)
{
pEndMarker->Update(pDefs);
pEndMarker->Draw(pRenderer, {*(arPoints.end() - 1)}, m_oStyles.m_oStroke.m_oWidth.ToDouble(NSCSS::Pixel));
pEndMarker->Draw(pRenderer, {*(arPoints.end() - 1)}, dStrokeWidth);
}
}

View File

@ -38,6 +38,10 @@
#include "../../../raster/BgraFrame.h"
#include "../../../common/Directory.h"
#include <algorithm>
#include <io.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
// Check system fonts
@ -48,11 +52,11 @@ int main(int argc, char *argv[])
if (!NSDirectory::Exists(oWorker.m_sDirectory))
NSDirectory::CreateDirectory(oWorker.m_sDirectory);
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
MetaFile::IMetaFile* pMetafile = MetaFile::Create(pFonts);
pMetafile->LoadFromFile(L"PATH_TO_METAFILE");
pMetafile->ConvertToRaster(L"PATH_TO_RASTER", 4, 1000);
MetaFile::IMetaFile* pMetafile = MetaFile::Create(pFonts);
pMetafile->LoadFromFile(L"C:/Users/Kirill.Polyakov.AVSMEDIA/Desktop/svg/TestMarker.svg");
pMetafile->ConvertToRaster(L"C:/Users/Kirill.Polyakov.AVSMEDIA/Desktop/test.png", 4, 3000);
pMetafile->Release();
pFonts->Release();

View File

@ -18,7 +18,7 @@ TEMPLATE = app
CORE_ROOT_DIR = $$PWD/../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
include($$CORE_ROOT_DIR/3dParty/icu/icu.pri)
include($$CORE_ROOT_DIR/Common/3dParty/icu/icu.pri)
ADD_DEPENDENCY(kernel, graphics, UnicodeConverter)
win32 {
@ -33,6 +33,5 @@ linux-g++ | linux-g++-64 | linux-g++-32 {
}
SOURCES += main.cpp
SOURCES += ../../../fontengine/ApplicationFontsWorker.cpp
DESTDIR = $$PWD_ROOT_DIR/build/$$CORE_BUILDS_PLATFORM_PREFIX/$$CORE_BUILDS_CONFIGURATION_PREFIX