mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-11 01:11:43 +08:00
Co-authored-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com> Co-committed-by: Alexander Trofimov <alexander.trofimov@onlyoffice.com>
179 lines
4.2 KiB
C++
179 lines
4.2 KiB
C++
/*
|
|
* Copyright (C) Ascensio System SIA, 2009-2026
|
|
*
|
|
* This program is a free software product. You can redistribute it and/or
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
* version 3 as published by the Free Software Foundation, together with the
|
|
* additional terms provided in the LICENSE file.
|
|
*
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
* details, see the GNU AGPL at: https://www.gnu.org/licenses/agpl-3.0.html
|
|
*
|
|
* You can contact Ascensio System SIA by email at info@onlyoffice.com
|
|
* or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga,
|
|
* LV-1050, Latvia, European Union.
|
|
*
|
|
* The interactive user interfaces in modified versions of the Program
|
|
* are required to display Appropriate Legal Notices in accordance with
|
|
* Section 5 of the GNU AGPL version 3.
|
|
*
|
|
* No trademark rights are granted under this License.
|
|
*
|
|
* All non-code elements of the Product, including illustrations,
|
|
* icon sets, and technical writing content, are licensed under the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License:
|
|
* https://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
*
|
|
* This license applies only to such non-code elements and does not
|
|
* modify or replace the licensing terms applicable to the Program's
|
|
* source code, which remains licensed under the GNU Affero General
|
|
* Public License v3.
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
#include "Outline.h"
|
|
#include "Destination.h"
|
|
|
|
#define OUTLINE_CLOSED 0
|
|
#define OUTLINE_OPENED 1
|
|
|
|
namespace PdfWriter
|
|
{
|
|
COutline::COutline(CXref* pXref)
|
|
{
|
|
pXref->Add(this);
|
|
|
|
CNumberObject* pOpenFlag = new CNumberObject(OUTLINE_OPENED);
|
|
if (!pOpenFlag)
|
|
return;
|
|
|
|
pOpenFlag->SetHidden();
|
|
|
|
Add("_OPENED", pOpenFlag);
|
|
Add("Type", "Outlines");
|
|
}
|
|
COutline::COutline(COutline* pParent, const char* sTitle, CXref* pXref)
|
|
{
|
|
if (!pParent || !pXref)
|
|
return;
|
|
|
|
pXref->Add(this);
|
|
|
|
CStringObject* pString = new CStringObject(sTitle, true);
|
|
if (!pString)
|
|
return;
|
|
|
|
Add("Title", pString);
|
|
|
|
CNumberObject* pOpenFlag = new CNumberObject(OUTLINE_OPENED);
|
|
if (!pOpenFlag)
|
|
return;
|
|
|
|
pOpenFlag->SetHidden();
|
|
|
|
Add("_OPENED", pOpenFlag);
|
|
Add("Type", "Outline");
|
|
|
|
pParent->AddChild(this);
|
|
}
|
|
void COutline::BeforeWrite()
|
|
{
|
|
CNumberObject* pNumber = (CNumberObject*)Get("Count");
|
|
unsigned int unCount = CountChild();
|
|
|
|
if (0 == unCount && pNumber)
|
|
return Remove("Count");
|
|
|
|
if (!GetOpened())
|
|
unCount *= -1;
|
|
|
|
if (pNumber)
|
|
pNumber->Set(unCount);
|
|
else if (unCount)
|
|
Add("Count", unCount);
|
|
}
|
|
void COutline::AddChild(COutline* pItem)
|
|
{
|
|
COutline* pFirst = (COutline*)Get("First");
|
|
COutline* pLast = (COutline*)Get("Last");
|
|
|
|
if (!pFirst)
|
|
Add("First", pItem);
|
|
|
|
if (pLast)
|
|
{
|
|
pLast->Add("Next", pItem);
|
|
pItem->Add("Prev", pLast);
|
|
}
|
|
|
|
Add("Last", pItem);
|
|
pItem->Add("Parent", this);
|
|
}
|
|
unsigned int COutline::CountChild()
|
|
{
|
|
COutline* pOutline = GetFirst();
|
|
unsigned int unCount = 0;
|
|
|
|
while (pOutline)
|
|
{
|
|
unCount++;
|
|
|
|
if (pOutline->GetOpened())
|
|
unCount += pOutline->CountChild();
|
|
|
|
pOutline = pOutline->GetNext();
|
|
}
|
|
|
|
return unCount;
|
|
}
|
|
COutline* COutline::GetFirst()
|
|
{
|
|
return (COutline*)Get("First");
|
|
}
|
|
COutline* COutline::GetLast ()
|
|
{
|
|
return (COutline*)Get("Last");
|
|
}
|
|
COutline* COutline::GetPrev ()
|
|
{
|
|
return (COutline*)Get("Prev");
|
|
}
|
|
COutline* COutline::GetNext ()
|
|
{
|
|
return (COutline*)Get("Next");
|
|
}
|
|
COutline* COutline::GetParent()
|
|
{
|
|
return (COutline*)Get("Parent");
|
|
}
|
|
bool COutline::GetOpened()
|
|
{
|
|
CNumberObject* pNumber = (CNumberObject*)Get("_OPENED");
|
|
|
|
if (!pNumber)
|
|
return false;
|
|
|
|
return (pNumber->Get() == OUTLINE_OPENED ? true : false);
|
|
}
|
|
void COutline::SetDestination(CDestination* pDestination)
|
|
{
|
|
if (NULL == pDestination)
|
|
Remove("Dest");
|
|
else
|
|
Add("Dest", pDestination);
|
|
}
|
|
void COutline::SetOpened(bool bOpened)
|
|
{
|
|
CNumberObject* pNumber = (CNumberObject*)Get("_OPENED");
|
|
if (!pNumber)
|
|
{
|
|
pNumber = new CNumberObject(bOpened ? OUTLINE_OPENED : OUTLINE_CLOSED);
|
|
if (pNumber)
|
|
Add("_OPENED", pNumber);
|
|
}
|
|
else
|
|
pNumber->Set(bOpened ? OUTLINE_OPENED : OUTLINE_CLOSED);
|
|
}
|
|
}
|