blob: 142504cf0110a2e2d5820b3ad8427b27cc6bbfca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/***************************************************************************
kbuffercoltextexport.cpp - description
-------------------
begin : Sam Aug 30 2003
copyright : (C) 2003 by Friedrich W. H. Kossebau
email : Friedrich.W.H@Kossebau.de
***************************************************************************/
/***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License version 2 as published by the Free Software Foundation. *
* *
***************************************************************************/
// c specific
#include <string.h>
// lib specific
#include "kbuffercolumn.h"
#include "kbufferlayout.h"
#include "kbuffercoltextexport.h"
using namespace KHE;
static const int DefaultTEByteSpacingWidth = 1;
static const int TEGroupSpacingWidth = 3;
TQString KBufferColTextExport::whiteSpace( uint s )
{
return TQString().fill( ' ', s );
}
KBufferColTextExport::KBufferColTextExport( const KBufferColumn* BufferColumn, const char *D,
KCoordRange CR, int ByteWidth )
: Data( D ),
CoordRange( CR )
{
NoOfBytesPerLine = BufferColumn->layout()->noOfBytesPerLine();
Pos = new int[NoOfBytesPerLine];
// TODO: remove this hack and make it more general
int ByteSpacingWidth = BufferColumn->byteSpacingWidth();
if( ByteSpacingWidth > 0 )
ByteSpacingWidth = DefaultTEByteSpacingWidth;
int SpacingTrigger = BufferColumn->noOfGroupedBytes()-1;
if( SpacingTrigger < 0 )
SpacingTrigger = NoOfBytesPerLine; // ensures to never trigger the group spacing
int N = 0;
int p = 0;
int gs = 0;
int *P = Pos;
for( ; P<&Pos[NoOfBytesPerLine]; ++P, ++p, ++gs )
{
*P = N;
N += ByteWidth;
// is there a space behind the actual byte (if it is not the last)?
if( gs == SpacingTrigger )
{
N += TEGroupSpacingWidth;
gs = -1;
}
else
N += ByteSpacingWidth;
}
N -= (gs==0)?TEGroupSpacingWidth:ByteSpacingWidth;
NoOfCharsPerLine = N;
}
KBufferColTextExport::~KBufferColTextExport()
{
delete [] Pos;
}
int KBufferColTextExport::charsPerLine() const
{
return NoOfCharsPerLine;
}
void KBufferColTextExport::printFirstLine( TQString &T, int Line ) const
{
PrintLine = Line;
PrintData = Data;
print( T );
}
void KBufferColTextExport::printNextLine( TQString &T ) const
{
print( T );
}
void KBufferColTextExport::print( TQString &T ) const
{
T.append( whiteSpace(NoOfCharsPerLine) );
++PrintLine;
}
|