File indexing completed on 2025-01-05 05:23:53

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2023 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "offsetcolumnhtmlrenderer.hpp"
0010 
0011 // Qt
0012 #include <QString>
0013 #include <QTextStream>
0014 
0015 namespace Kasten {
0016 
0017 OffsetColumnHtmlRenderer::OffsetColumnHtmlRenderer(int offsetFormat, int firstLineOffset, int delta, bool columnMode)
0018     : mFirstLineOffset(firstLineOffset)
0019     , mDelta(delta)
0020     , printFunction(Okteta::OffsetFormat::printFunction(offsetFormat))
0021     , mCodingWidth(Okteta::OffsetFormat::codingWidth(offsetFormat))
0022     , mColumnMode(columnMode)
0023 {
0024     mEncodedOffsetBuffer = new char[mCodingWidth + 1];
0025 }
0026 
0027 OffsetColumnHtmlRenderer::~OffsetColumnHtmlRenderer()
0028 {
0029     delete [] mEncodedOffsetBuffer;
0030 }
0031 
0032 void OffsetColumnHtmlRenderer::renderFirstLine(QTextStream* stream, int lineIndex) const
0033 {
0034     mRenderLine = lineIndex;
0035     renderLine(stream, false);
0036 }
0037 
0038 void OffsetColumnHtmlRenderer::renderNextLine(QTextStream* stream, bool isSubline) const
0039 {
0040     renderLine(stream, isSubline);
0041 }
0042 
0043 void OffsetColumnHtmlRenderer::renderLine(QTextStream* stream, bool isSubline) const
0044 {
0045     if (mColumnMode) {
0046         *stream << "<th nowrap>";
0047     } else {
0048         if (!isSubline) {
0049             *stream << "<th nowrap rowspan=2 valign=top>";
0050         }
0051     }
0052     if (!isSubline) {
0053         // TODO: fix me (no more printFunction)
0054         printFunction(mEncodedOffsetBuffer, mFirstLineOffset + mDelta * mRenderLine);
0055         *stream << "<tt>" << mEncodedOffsetBuffer << "</tt>";
0056 
0057         ++mRenderLine;
0058     }
0059     if (mColumnMode || !isSubline) {
0060         *stream << "</th>";
0061     }
0062 }
0063 
0064 }