Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
aa6a893a
Commit
aa6a893a
authored
Jan 26, 2012
by
Aleksei Kanash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SANKORE-463 (testet for ubuntu 11 x86_64)
parent
9f898048
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
86 additions
and
86 deletions
+86
-86
ASCIIHexDecode.cpp
src/pdf-merger/ASCIIHexDecode.cpp
+1
-1
AbstractBoxElementHandler.h
src/pdf-merger/AbstractBoxElementHandler.h
+2
-2
AnnotsHandler.cpp
src/pdf-merger/AnnotsHandler.cpp
+2
-2
Filter.cpp
src/pdf-merger/Filter.cpp
+2
-2
FilterPredictor.cpp
src/pdf-merger/FilterPredictor.cpp
+4
-4
FlateDecode.cpp
src/pdf-merger/FlateDecode.cpp
+1
-1
LZWDecode.cpp
src/pdf-merger/LZWDecode.cpp
+1
-1
MediaBoxElementHandler.h
src/pdf-merger/MediaBoxElementHandler.h
+1
-1
Object.cpp
src/pdf-merger/Object.cpp
+6
-6
Page.cpp
src/pdf-merger/Page.cpp
+13
-13
PageElementHandler.cpp
src/pdf-merger/PageElementHandler.cpp
+2
-2
PageElementHandler.h
src/pdf-merger/PageElementHandler.h
+2
-2
Parser.cpp
src/pdf-merger/Parser.cpp
+46
-46
Rectangle.cpp
src/pdf-merger/Rectangle.cpp
+3
-3
No files found.
src/pdf-merger/ASCIIHexDecode.cpp
View file @
aa6a893a
...
@@ -51,7 +51,7 @@ bool ASCIIHexDecode::decode(std::string & encoded)
...
@@ -51,7 +51,7 @@ bool ASCIIHexDecode::decode(std::string & encoded)
for
(
int
i
=
0
;
i
<
len
;
i
++
)
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
{
unsigned
char
ch
=
encoded
[
i
];
unsigned
char
ch
=
encoded
[
i
];
if
(
WHITESPACES
.
find
(
ch
)
!=
std
::
string
::
npos
)
if
(
WHITESPACES
.
find
(
ch
)
!=
-
1
)
{
{
continue
;
continue
;
}
}
...
...
src/pdf-merger/AbstractBoxElementHandler.h
View file @
aa6a893a
...
@@ -42,7 +42,7 @@ namespace merge_lib
...
@@ -42,7 +42,7 @@ namespace merge_lib
{
{
unsigned
int
startOfParent
=
content
.
find
(
"/Parent"
);
unsigned
int
startOfParent
=
content
.
find
(
"/Parent"
);
unsigned
int
endOfParent
=
content
.
find
(
" R"
,
startOfParent
);
unsigned
int
endOfParent
=
content
.
find
(
" R"
,
startOfParent
);
if
(
startOfParent
==
std
::
string
::
npos
)
if
(
startOfParent
==
-
1
)
break
;
break
;
std
::
vector
<
Object
*>
parents
=
parent
->
getChildrenByBounds
(
startOfParent
,
endOfParent
);
std
::
vector
<
Object
*>
parents
=
parent
->
getChildrenByBounds
(
startOfParent
,
endOfParent
);
if
(
parents
.
size
()
!=
1
)
if
(
parents
.
size
()
!=
1
)
...
@@ -50,7 +50,7 @@ namespace merge_lib
...
@@ -50,7 +50,7 @@ namespace merge_lib
parent
=
parents
[
0
];
parent
=
parents
[
0
];
std
::
string
parentContent
=
parent
->
getObjectContent
();
std
::
string
parentContent
=
parent
->
getObjectContent
();
unsigned
int
startOfMediaBox
=
parentContent
.
find
(
_handlerName
);
unsigned
int
startOfMediaBox
=
parentContent
.
find
(
_handlerName
);
if
(
startOfMediaBox
==
std
::
string
::
npos
)
if
(
startOfMediaBox
==
-
1
)
{
{
content
=
parentContent
;
content
=
parentContent
;
continue
;
continue
;
...
...
src/pdf-merger/AnnotsHandler.cpp
View file @
aa6a893a
...
@@ -36,8 +36,8 @@ void AnnotsHandler::_processObjectContent(unsigned int startOfPageElement)
...
@@ -36,8 +36,8 @@ void AnnotsHandler::_processObjectContent(unsigned int startOfPageElement)
{
{
Object
*
child
=
_annotations
[
0
];
Object
*
child
=
_annotations
[
0
];
std
::
string
childContent
=
child
->
getObjectContent
();
std
::
string
childContent
=
child
->
getObjectContent
();
if
(
Parser
::
findToken
(
childContent
,
"/Rect"
)
==
std
::
string
::
npos
&&
if
(
Parser
::
findToken
(
childContent
,
"/Rect"
)
==
-
1
&&
Parser
::
findToken
(
childContent
,
"/Subtype"
)
==
std
::
string
::
npos
)
Parser
::
findToken
(
childContent
,
"/Subtype"
)
==
-
1
)
{
{
// this was not Annotation but reference to array
// this was not Annotation but reference to array
// of annotations
// of annotations
...
...
src/pdf-merger/Filter.cpp
View file @
aa6a893a
...
@@ -63,12 +63,12 @@ std::vector <Decoder * > Filter::_getDecoders()
...
@@ -63,12 +63,12 @@ std::vector <Decoder * > Filter::_getDecoders()
while
(
1
)
while
(
1
)
{
{
startOfDecoder
=
streamHeader
.
find
(
"/"
,
startOfDecoder
);
startOfDecoder
=
streamHeader
.
find
(
"/"
,
startOfDecoder
);
if
(
startOfDecoder
==
std
::
string
::
npos
)
if
(
startOfDecoder
==
-
1
)
break
;
break
;
else
else
++
startOfDecoder
;
++
startOfDecoder
;
unsigned
int
endOfDecoder
=
streamHeader
.
find_first_of
(
whitespacesAndDelimeters
,
startOfDecoder
);
unsigned
int
endOfDecoder
=
streamHeader
.
find_first_of
(
whitespacesAndDelimeters
,
startOfDecoder
);
if
(
endOfDecoder
==
std
::
string
::
npos
)
if
(
endOfDecoder
==
-
1
)
break
;
break
;
std
::
map
<
std
::
string
,
Decoder
*>::
iterator
foundDecoder
=
std
::
map
<
std
::
string
,
Decoder
*>::
iterator
foundDecoder
=
_allDecoders
.
find
(
streamHeader
.
substr
(
startOfDecoder
,
endOfDecoder
-
startOfDecoder
));
_allDecoders
.
find
(
streamHeader
.
substr
(
startOfDecoder
,
endOfDecoder
-
startOfDecoder
));
...
...
src/pdf-merger/FilterPredictor.cpp
View file @
aa6a893a
...
@@ -52,14 +52,14 @@ FilterPredictor::~FilterPredictor()
...
@@ -52,14 +52,14 @@ FilterPredictor::~FilterPredictor()
std
::
string
FilterPredictor
::
getDictionaryContentStr
(
std
::
string
&
in
,
size_t
&
pos
)
std
::
string
FilterPredictor
::
getDictionaryContentStr
(
std
::
string
&
in
,
size_t
&
pos
)
{
{
size_t
beg
=
in
.
find
(
DICT_START_TOKEN
,
pos
);
size_t
beg
=
in
.
find
(
DICT_START_TOKEN
,
pos
);
if
(
beg
==
std
::
string
::
npos
)
if
(
beg
==
-
1
)
{
{
return
""
;
return
""
;
}
}
beg
+=
DICT_START_TOKEN
.
size
();
beg
+=
DICT_START_TOKEN
.
size
();
size_t
end
=
in
.
find
(
DICT_END_TOKEN
,
beg
);
size_t
end
=
in
.
find
(
DICT_END_TOKEN
,
beg
);
if
(
end
==
std
::
string
::
npos
)
if
(
end
==
-
1
)
{
{
return
""
;
return
""
;
}
}
...
@@ -85,7 +85,7 @@ void FilterPredictor::obtainDecodeParams(Object *objectWithStream, std::string &
...
@@ -85,7 +85,7 @@ void FilterPredictor::obtainDecodeParams(Object *objectWithStream, std::string &
for
(;
it
!=
params
.
end
();
it
++
)
for
(;
it
!=
params
.
end
();
it
++
)
{
{
size_t
pos
=
dictStr
.
find
((
*
it
).
first
);
size_t
pos
=
dictStr
.
find
((
*
it
).
first
);
if
(
pos
!=
std
::
string
::
npos
)
if
(
pos
!=
-
1
)
{
{
pos
+=
(
*
it
).
first
.
size
();
pos
+=
(
*
it
).
first
.
size
();
...
@@ -116,7 +116,7 @@ void FilterPredictor::initialize(Object *objectWithStream)
...
@@ -116,7 +116,7 @@ void FilterPredictor::initialize(Object *objectWithStream)
objectWithStream
->
getHeader
(
content
);
objectWithStream
->
getHeader
(
content
);
// we need to parse the header of file to obtain the decoder parameter
// we need to parse the header of file to obtain the decoder parameter
size_t
position
=
content
.
find
(
DECODE_PARAM_TOKEN
);
size_t
position
=
content
.
find
(
DECODE_PARAM_TOKEN
);
if
(
position
!=
std
::
string
::
npos
)
if
(
position
!=
-
1
)
{
{
position
+=
DECODE_PARAM_TOKEN
.
size
();
position
+=
DECODE_PARAM_TOKEN
.
size
();
std
::
string
dictStr
=
getDictionaryContentStr
(
content
,
position
);
std
::
string
dictStr
=
getDictionaryContentStr
(
content
,
position
);
...
...
src/pdf-merger/FlateDecode.cpp
View file @
aa6a893a
...
@@ -47,7 +47,7 @@ void FlateDecode::initialize(Object * objectWithStream)
...
@@ -47,7 +47,7 @@ void FlateDecode::initialize(Object * objectWithStream)
std
::
string
head
;
std
::
string
head
;
objectWithStream
->
getHeader
(
head
);
objectWithStream
->
getHeader
(
head
);
if
(
head
.
find
(
FilterPredictor
::
DECODE_PARAM_TOKEN
)
!=
std
::
string
::
npos
)
if
(
head
.
find
(
FilterPredictor
::
DECODE_PARAM_TOKEN
)
!=
-
1
)
{
{
_predict
=
new
FilterPredictor
();
_predict
=
new
FilterPredictor
();
_predict
->
initialize
(
objectWithStream
);
_predict
->
initialize
(
objectWithStream
);
...
...
src/pdf-merger/LZWDecode.cpp
View file @
aa6a893a
...
@@ -51,7 +51,7 @@ void LZWDecode::initialize(Object * objectWithStream)
...
@@ -51,7 +51,7 @@ void LZWDecode::initialize(Object * objectWithStream)
std
::
string
head
;
std
::
string
head
;
objectWithStream
->
getHeader
(
head
);
objectWithStream
->
getHeader
(
head
);
if
(
head
.
find
(
FilterPredictor
::
DECODE_PARAM_TOKEN
)
!=
std
::
string
::
npos
)
if
(
head
.
find
(
FilterPredictor
::
DECODE_PARAM_TOKEN
)
!=
-
1
)
{
{
_predict
=
new
FilterPredictor
();
_predict
=
new
FilterPredictor
();
_predict
->
initialize
(
objectWithStream
);
_predict
->
initialize
(
objectWithStream
);
...
...
src/pdf-merger/MediaBoxElementHandler.h
View file @
aa6a893a
...
@@ -59,7 +59,7 @@ namespace merge_lib
...
@@ -59,7 +59,7 @@ namespace merge_lib
}
}
bool
_wasCropBoxHandlerCalled
()
bool
_wasCropBoxHandlerCalled
()
{
{
return
(
_page
->
getObjectContent
().
find
(
"/BBox"
)
!=
std
::
string
::
npos
)
?
true
:
false
;
return
(
_page
->
getObjectContent
().
find
(
"/BBox"
)
!=
-
1
)
?
true
:
false
;
}
}
};
};
}
}
...
...
src/pdf-merger/Object.cpp
View file @
aa6a893a
...
@@ -369,7 +369,7 @@ bool Object::_findObject(const std::string & token, Object* & foundObject, unsig
...
@@ -369,7 +369,7 @@ bool Object::_findObject(const std::string & token, Object* & foundObject, unsig
{
{
_isPassed
=
true
;
_isPassed
=
true
;
tokenPositionInContent
=
Parser
::
findToken
(
_content
,
token
);
tokenPositionInContent
=
Parser
::
findToken
(
_content
,
token
);
if
(
tokenPositionInContent
!=
std
::
string
::
npos
)
if
(
tokenPositionInContent
!=
-
1
)
{
{
foundObject
=
this
;
foundObject
=
this
;
return
true
;
return
true
;
...
@@ -456,12 +456,12 @@ bool Object::getStream(std::string & stream)
...
@@ -456,12 +456,12 @@ bool Object::getStream(std::string & stream)
bool
Object
::
_getStreamFromContent
(
std
::
string
&
stream
)
bool
Object
::
_getStreamFromContent
(
std
::
string
&
stream
)
{
{
size_t
stream_begin
=
_content
.
find
(
"stream"
);
size_t
stream_begin
=
_content
.
find
(
"stream"
);
if
(
stream_begin
==
std
::
string
::
npos
)
if
(
stream_begin
==
-
1
)
{
{
return
false
;
return
false
;
}
}
size_t
stream_end
=
_content
.
find
(
"endstream"
,
stream_begin
);
size_t
stream_end
=
_content
.
find
(
"endstream"
,
stream_begin
);
if
(
stream_end
==
std
::
string
::
npos
)
if
(
stream_end
==
-
1
)
{
{
return
false
;
return
false
;
}
}
...
@@ -558,7 +558,7 @@ std::string Object::getNameSimpleValue(const std::string &content, const std::st
...
@@ -558,7 +558,7 @@ std::string Object::getNameSimpleValue(const std::string &content, const std::st
Object
*
Object
::
findPatternInObjOrParents
(
const
std
::
string
&
pattern
)
Object
*
Object
::
findPatternInObjOrParents
(
const
std
::
string
&
pattern
)
{
{
std
::
string
content
=
getObjectContent
();
std
::
string
content
=
getObjectContent
();
if
(
Parser
::
findToken
(
content
,
pattern
,
0
)
!=
std
::
string
::
npos
)
if
(
Parser
::
findToken
(
content
,
pattern
,
0
)
!=
-
1
)
{
{
return
this
;
return
this
;
}
}
...
@@ -569,7 +569,7 @@ Object* Object::findPatternInObjOrParents(const std::string &pattern)
...
@@ -569,7 +569,7 @@ Object* Object::findPatternInObjOrParents(const std::string &pattern)
{
{
unsigned
int
startOfParent
=
content
.
find
(
"/Parent"
);
unsigned
int
startOfParent
=
content
.
find
(
"/Parent"
);
unsigned
int
endOfParent
=
content
.
find
(
" R"
,
startOfParent
);
unsigned
int
endOfParent
=
content
.
find
(
" R"
,
startOfParent
);
if
(
startOfParent
==
std
::
string
::
npos
)
if
(
startOfParent
==
-
1
)
{
{
break
;
break
;
}
}
...
@@ -581,7 +581,7 @@ Object* Object::findPatternInObjOrParents(const std::string &pattern)
...
@@ -581,7 +581,7 @@ Object* Object::findPatternInObjOrParents(const std::string &pattern)
parent
=
parents
[
0
];
parent
=
parents
[
0
];
std
::
string
parentContent
=
parent
->
getObjectContent
();
std
::
string
parentContent
=
parent
->
getObjectContent
();
unsigned
int
startOfPattern
=
parentContent
.
find
(
pattern
);
unsigned
int
startOfPattern
=
parentContent
.
find
(
pattern
);
if
(
startOfPattern
==
std
::
string
::
npos
)
if
(
startOfPattern
==
-
1
)
{
{
content
=
parentContent
;
content
=
parentContent
;
continue
;
continue
;
...
...
src/pdf-merger/Page.cpp
View file @
aa6a893a
...
@@ -193,7 +193,7 @@ static void _updateAnnotParentPage(Object *annotation,Object *newParentPage)
...
@@ -193,7 +193,7 @@ static void _updateAnnotParentPage(Object *annotation,Object *newParentPage)
std
::
string
&
annotContent
=
annotation
->
getObjectContent
();
std
::
string
&
annotContent
=
annotation
->
getObjectContent
();
size_t
startOfP
=
Parser
::
findTokenName
(
annotContent
,
strP
);
size_t
startOfP
=
Parser
::
findTokenName
(
annotContent
,
strP
);
if
(
startOfP
==
std
::
string
::
npos
)
if
(
startOfP
==
-
1
)
{
{
return
;
return
;
}
}
...
@@ -229,12 +229,12 @@ static void _updateAnnotParentPage(Object *annotation,Object *newParentPage)
...
@@ -229,12 +229,12 @@ static void _updateAnnotParentPage(Object *annotation,Object *newParentPage)
static
void
_updateAnnotFormColor
(
Object
*
annotation
)
static
void
_updateAnnotFormColor
(
Object
*
annotation
)
{
{
std
::
string
&
objectContent
=
annotation
->
getObjectContent
();
std
::
string
&
objectContent
=
annotation
->
getObjectContent
();
if
(
objectContent
.
find
(
"/Widget"
)
==
std
::
string
::
npos
)
if
(
objectContent
.
find
(
"/Widget"
)
==
-
1
)
{
{
return
;
return
;
}
}
size_t
startOfAP
=
Parser
::
findTokenName
(
objectContent
,
"/AP"
);
size_t
startOfAP
=
Parser
::
findTokenName
(
objectContent
,
"/AP"
);
if
(
startOfAP
==
std
::
string
::
npos
)
if
(
startOfAP
==
-
1
)
{
{
return
;
return
;
}
}
...
@@ -262,7 +262,7 @@ static void _updateAnnotFormColor(Object *annotation )
...
@@ -262,7 +262,7 @@ static void _updateAnnotFormColor(Object *annotation )
{
{
if
(
token
==
"f"
||
token
==
"F"
)
if
(
token
==
"f"
||
token
==
"F"
)
{
{
if
(
found
!=
std
::
string
::
npos
)
if
(
found
!=
-
1
)
{
{
decodedStream
[
found
]
=
' '
;
decodedStream
[
found
]
=
' '
;
}
}
...
@@ -272,7 +272,7 @@ static void _updateAnnotFormColor(Object *annotation )
...
@@ -272,7 +272,7 @@ static void _updateAnnotFormColor(Object *annotation )
// Then we need to update Filter section (if any)
// Then we need to update Filter section (if any)
std
::
string
filterStr
=
"/Filter"
;
std
::
string
filterStr
=
"/Filter"
;
size_t
startOfFlate
=
Parser
::
findTokenName
(
content
,
filterStr
);
size_t
startOfFlate
=
Parser
::
findTokenName
(
content
,
filterStr
);
if
(
startOfFlate
!=
std
::
string
::
npos
)
if
(
startOfFlate
!=
-
1
)
{
{
size_t
endOfFlate
=
Parser
::
findEndOfElementContent
(
content
,
startOfFlate
+
filterStr
.
size
());
size_t
endOfFlate
=
Parser
::
findEndOfElementContent
(
content
,
startOfFlate
+
filterStr
.
size
());
childWithAP
->
eraseContent
(
startOfFlate
,
endOfFlate
-
startOfFlate
);
childWithAP
->
eraseContent
(
startOfFlate
,
endOfFlate
-
startOfFlate
);
...
@@ -285,7 +285,7 @@ static void _updateAnnotFormColor(Object *annotation )
...
@@ -285,7 +285,7 @@ static void _updateAnnotFormColor(Object *annotation )
// update the length field
// update the length field
std
::
string
lengthStr
=
"/Length"
;
std
::
string
lengthStr
=
"/Length"
;
size_t
startOfLength
=
Parser
::
findTokenName
(
content
,
lengthStr
,
0
);
size_t
startOfLength
=
Parser
::
findTokenName
(
content
,
lengthStr
,
0
);
if
(
startOfLength
!=
std
::
string
::
npos
)
if
(
startOfLength
!=
-
1
)
{
{
size_t
endOfLength
=
Parser
::
findEndOfElementContent
(
content
,
startOfLength
+
lengthStr
.
size
());
size_t
endOfLength
=
Parser
::
findEndOfElementContent
(
content
,
startOfLength
+
lengthStr
.
size
());
childWithAP
->
eraseContent
(
startOfLength
,
endOfLength
-
startOfLength
);
childWithAP
->
eraseContent
(
startOfLength
,
endOfLength
-
startOfLength
);
...
@@ -296,10 +296,10 @@ static void _updateAnnotFormColor(Object *annotation )
...
@@ -296,10 +296,10 @@ static void _updateAnnotFormColor(Object *annotation )
// update the stream of object with new content
// update the stream of object with new content
std
::
string
stream
(
"stream"
);
std
::
string
stream
(
"stream"
);
size_t
leftBoundOfContentStream
=
content
.
find
(
stream
);
size_t
leftBoundOfContentStream
=
content
.
find
(
stream
);
if
(
leftBoundOfContentStream
!=
std
::
string
::
npos
)
if
(
leftBoundOfContentStream
!=
-
1
)
{
{
size_t
rightBoundOfContentStream
=
content
.
find
(
"endstream"
,
leftBoundOfContentStream
);
size_t
rightBoundOfContentStream
=
content
.
find
(
"endstream"
,
leftBoundOfContentStream
);
if
(
rightBoundOfContentStream
==
std
::
string
::
npos
)
if
(
rightBoundOfContentStream
==
-
1
)
{
{
rightBoundOfContentStream
=
content
.
size
()
-
1
;
rightBoundOfContentStream
=
content
.
size
()
-
1
;
}
}
...
@@ -323,7 +323,7 @@ static void processBasePageResources(Object *basePage)
...
@@ -323,7 +323,7 @@ static void processBasePageResources(Object *basePage)
return
;
return
;
}
}
std
::
string
resourceToken
=
"/Resources"
;
std
::
string
resourceToken
=
"/Resources"
;
if
(
Parser
::
findTokenName
(
basePage
->
getObjectContent
(),
resourceToken
)
==
std
::
string
::
npos
)
if
(
Parser
::
findTokenName
(
basePage
->
getObjectContent
(),
resourceToken
)
==
-
1
)
{
{
// it seems base page does not have resources, they can be located in parent!
// it seems base page does not have resources, they can be located in parent!
Object
*
resource
=
basePage
->
findPatternInObjOrParents
(
resourceToken
);
Object
*
resource
=
basePage
->
findPatternInObjOrParents
(
resourceToken
);
...
@@ -331,20 +331,20 @@ static void processBasePageResources(Object *basePage)
...
@@ -331,20 +331,20 @@ static void processBasePageResources(Object *basePage)
{
{
std
::
string
&
resContStr
=
resource
->
getObjectContent
();
std
::
string
&
resContStr
=
resource
->
getObjectContent
();
size_t
startOfRes
=
Parser
::
findTokenName
(
resContStr
,
resourceToken
);
size_t
startOfRes
=
Parser
::
findTokenName
(
resContStr
,
resourceToken
);
if
(
startOfRes
==
std
::
string
::
npos
)
if
(
startOfRes
==
-
1
)
{
{
// no resources at all
// no resources at all
return
;
return
;
}
}
size_t
endOfRes
=
Parser
::
findEndOfElementContent
(
resContStr
,
startOfRes
+
resourceToken
.
size
());
size_t
endOfRes
=
Parser
::
findEndOfElementContent
(
resContStr
,
startOfRes
+
resourceToken
.
size
());
if
(
endOfRes
==
std
::
string
::
npos
)
if
(
endOfRes
==
-
1
)
{
{
return
;
// broken resources
return
;
// broken resources
}
}
std
::
string
resourceContent
=
resContStr
.
substr
(
startOfRes
,
endOfRes
-
startOfRes
);
std
::
string
resourceContent
=
resContStr
.
substr
(
startOfRes
,
endOfRes
-
startOfRes
);
size_t
positionToInsert
=
basePage
->
getObjectContent
().
find
(
"<<"
);
size_t
positionToInsert
=
basePage
->
getObjectContent
().
find
(
"<<"
);
if
(
positionToInsert
==
std
::
string
::
npos
)
if
(
positionToInsert
==
-
1
)
{
{
positionToInsert
=
0
;
positionToInsert
=
0
;
resourceContent
.
insert
(
0
,
"<<"
);
resourceContent
.
insert
(
0
,
"<<"
);
...
@@ -479,7 +479,7 @@ void Page::merge(Page * sourcePage, Document * parentDocument, MergePageDescript
...
@@ -479,7 +479,7 @@ void Page::merge(Page * sourcePage, Document * parentDocument, MergePageDescript
rotationHandler
.
processObjectContent
();
rotationHandler
.
processObjectContent
();
description
.
basePageTransformation
.
addRotation
(
_rotation
);
description
.
basePageTransformation
.
addRotation
(
_rotation
);
if
(
sourcePage
->
_root
->
getObjectContent
().
find
(
"/Annots"
)
!=
std
::
string
::
npos
)
if
(
sourcePage
->
_root
->
getObjectContent
().
find
(
"/Annots"
)
!=
-
1
)
{
{
Object
*
crop
=
sourcePage
->
_root
->
findPatternInObjOrParents
(
"/CropBox"
);
Object
*
crop
=
sourcePage
->
_root
->
findPatternInObjOrParents
(
"/CropBox"
);
if
(
crop
)
if
(
crop
)
...
...
src/pdf-merger/PageElementHandler.cpp
View file @
aa6a893a
...
@@ -72,10 +72,10 @@ unsigned int PageElementHandler::_findEndOfElementContent(unsigned int startOfPa
...
@@ -72,10 +72,10 @@ unsigned int PageElementHandler::_findEndOfElementContent(unsigned int startOfPa
static
std
::
string
whitespacesAndDelimeters
(
"
\t\f\v\n\r
<<[/"
);
static
std
::
string
whitespacesAndDelimeters
(
"
\t\f\v\n\r
<<[/"
);
unsigned
int
foundSlash
=
_pageContent
.
find
(
"/"
,
startOfPageElement
+
1
);
unsigned
int
foundSlash
=
_pageContent
.
find
(
"/"
,
startOfPageElement
+
1
);
std
::
string
fieldType
;
std
::
string
fieldType
;
while
(
foundSlash
!=
std
::
string
::
npos
)
while
(
foundSlash
!=
-
1
)
{
{
unsigned
int
foundWhitespace
=
_pageContent
.
find_first_of
(
whitespacesAndDelimeters
,
foundSlash
+
1
);
unsigned
int
foundWhitespace
=
_pageContent
.
find_first_of
(
whitespacesAndDelimeters
,
foundSlash
+
1
);
if
(
foundWhitespace
!=
std
::
string
::
npos
)
if
(
foundWhitespace
!=
-
1
)
fieldType
=
_pageContent
.
substr
(
foundSlash
+
1
,
foundWhitespace
-
foundSlash
-
1
);
fieldType
=
_pageContent
.
substr
(
foundSlash
+
1
,
foundWhitespace
-
foundSlash
-
1
);
else
else
break
;
break
;
...
...
src/pdf-merger/PageElementHandler.h
View file @
aa6a893a
...
@@ -46,7 +46,7 @@ namespace merge_lib
...
@@ -46,7 +46,7 @@ namespace merge_lib
void
processObjectContent
()
void
processObjectContent
()
{
{
unsigned
int
startOfPageElement
=
_findStartOfPageElement
();
unsigned
int
startOfPageElement
=
_findStartOfPageElement
();
if
(
startOfPageElement
!=
std
::
string
::
npos
)
if
(
startOfPageElement
!=
-
1
)
_processObjectContent
(
startOfPageElement
);
_processObjectContent
(
startOfPageElement
);
if
(
_nextHandler
)
if
(
_nextHandler
)
_nextHandler
->
processObjectContent
();
_nextHandler
->
processObjectContent
();
...
@@ -55,7 +55,7 @@ namespace merge_lib
...
@@ -55,7 +55,7 @@ namespace merge_lib
void
changeObjectContent
()
void
changeObjectContent
()
{
{
unsigned
int
startOfPageElement
=
_findStartOfPageElement
();
unsigned
int
startOfPageElement
=
_findStartOfPageElement
();
if
(
startOfPageElement
!=
std
::
string
::
npos
)
if
(
startOfPageElement
!=
-
1
)
_changeObjectContent
(
startOfPageElement
);
_changeObjectContent
(
startOfPageElement
);
else
else
_pageElementNotFound
();
_pageElementNotFound
();
...
...
src/pdf-merger/Parser.cpp
View file @
aa6a893a
...
@@ -57,8 +57,8 @@ void Parser::_retrieveAllPages(Object * objectWithKids)
...
@@ -57,8 +57,8 @@ void Parser::_retrieveAllPages(Object * objectWithKids)
unsigned
int
startOfKids
=
objectContent
.
find
(
"/Kids"
);
unsigned
int
startOfKids
=
objectContent
.
find
(
"/Kids"
);
unsigned
int
endOfKids
=
objectContent
.
find
(
"]"
,
startOfKids
);
unsigned
int
endOfKids
=
objectContent
.
find
(
"]"
,
startOfKids
);
if
(
if
(
(
startOfKids
==
std
::
string
::
npos
)
&&
(
startOfKids
==
-
1
)
&&
(
objectContent
.
find
(
"/Page"
)
!=
std
::
string
::
npos
)
(
objectContent
.
find
(
"/Page"
)
!=
-
1
)
)
)
{
{
unsigned
int
numberOfPages
=
_document
->
_pages
.
size
()
+
1
;
unsigned
int
numberOfPages
=
_document
->
_pages
.
size
()
+
1
;
...
@@ -81,7 +81,7 @@ void Parser::_createDocument(const char * docName)
...
@@ -81,7 +81,7 @@ void Parser::_createDocument(const char * docName)
Object
*
objectWithPages
=
0
;
Object
*
objectWithPages
=
0
;
std
::
string
&
rootContent
=
_root
->
getObjectContent
();
std
::
string
&
rootContent
=
_root
->
getObjectContent
();
unsigned
int
startOfPages
=
rootContent
.
find
(
"/Pages"
);
unsigned
int
startOfPages
=
rootContent
.
find
(
"/Pages"
);
if
(
startOfPages
==
std
::
string
::
npos
)
if
(
startOfPages
==
-
1
)
throw
Exception
(
"Some document is wrong"
);
throw
Exception
(
"Some document is wrong"
);
unsigned
int
endOfPages
=
rootContent
.
find
(
"R"
,
startOfPages
);
unsigned
int
endOfPages
=
rootContent
.
find
(
"R"
,
startOfPages
);
std
::
vector
<
Object
*>
objectWithKids
=
_root
->
getChildrenByBounds
(
startOfPages
,
endOfPages
);
std
::
vector
<
Object
*>
objectWithKids
=
_root
->
getChildrenByBounds
(
startOfPages
,
endOfPages
);
...
@@ -187,19 +187,19 @@ const std::map<unsigned int, Object::ReferencePositionsInContent> & Parser::_get
...
@@ -187,19 +187,19 @@ const std::map<unsigned int, Object::ReferencePositionsInContent> & Parser::_get
static
std
::
map
<
unsigned
int
,
std
::
vector
<
unsigned
int
>
>
searchResult
;
static
std
::
map
<
unsigned
int
,
std
::
vector
<
unsigned
int
>
>
searchResult
;
searchResult
.
clear
();
searchResult
.
clear
();
unsigned
int
streamStart
=
objectContent
.
find
(
"stream"
);
unsigned
int
streamStart
=
objectContent
.
find
(
"stream"
);
if
(
streamStart
==
string
::
npos
)
if
(
streamStart
==
-
1
)
streamStart
=
objectContent
.
size
();
streamStart
=
objectContent
.
size
();
while
(
startOfNextSearch
<
streamStart
)
while
(
startOfNextSearch
<
streamStart
)
{
{
//try to find reference. reference example is 15 0 R
//try to find reference. reference example is 15 0 R
startOfNextSearch
=
objectContent
.
find
(
" R"
,
startOfNextSearch
);
startOfNextSearch
=
objectContent
.
find
(
" R"
,
startOfNextSearch
);
currentPosition
=
startOfNextSearch
;
currentPosition
=
startOfNextSearch
;
if
(
currentPosition
!=
std
::
string
::
npos
)
if
(
currentPosition
!=
-
1
)
{
{
//check that next character of " R" is WHITESPACE.
//check that next character of " R" is WHITESPACE.
if
((
WHITESPACES
.
find
(
objectContent
[
currentPosition
+
2
])
==
string
::
npos
)
&&
if
((
WHITESPACES
.
find
(
objectContent
[
currentPosition
+
2
])
==
-
1
)
&&
(
DELIMETERS
.
find
(
objectContent
[
currentPosition
+
2
])
==
string
::
npos
)
(
DELIMETERS
.
find
(
objectContent
[
currentPosition
+
2
])
==
-
1
)
)
)
{
{
//this is not reference. this is something looks like "0 0 0 RG"
//this is not reference. this is something looks like "0 0 0 RG"
...
@@ -257,7 +257,7 @@ const std::map<unsigned int, Object::ReferencePositionsInContent> & Parser::_get
...
@@ -257,7 +257,7 @@ const std::map<unsigned int, Object::ReferencePositionsInContent> & Parser::_get
unsigned
int
Parser
::
_skipNumber
(
const
std
::
string
&
str
,
unsigned
int
currentPosition
)
unsigned
int
Parser
::
_skipNumber
(
const
std
::
string
&
str
,
unsigned
int
currentPosition
)
{
{
unsigned
int
numberSearchCounter
=
currentPosition
;
unsigned
int
numberSearchCounter
=
currentPosition
;
while
((
NUMBERS
.
find
(
str
[
numberSearchCounter
])
!=
string
::
npos
)
&&
--
numberSearchCounter
)
while
((
NUMBERS
.
find
(
str
[
numberSearchCounter
])
!=
-
1
)
&&
--
numberSearchCounter
)
{}
{}
return
numberSearchCounter
;
return
numberSearchCounter
;
...
@@ -367,10 +367,10 @@ const std::pair<unsigned int, unsigned int> & Parser::_getLineBounds(const std::
...
@@ -367,10 +367,10 @@ const std::pair<unsigned int, unsigned int> & Parser::_getLineBounds(const std::
{
{
static
std
::
pair
<
unsigned
int
,
unsigned
int
>
bounds
;
static
std
::
pair
<
unsigned
int
,
unsigned
int
>
bounds
;
bounds
.
first
=
str
.
rfind
(
'\n'
,
fromPosition
);
bounds
.
first
=
str
.
rfind
(
'\n'
,
fromPosition
);
if
(
bounds
.
first
==
string
::
npos
)
if
(
bounds
.
first
==
-
1
)
bounds
.
first
=
0
;
bounds
.
first
=
0
;
bounds
.
second
=
str
.
find
(
'\n'
,
fromPosition
);
bounds
.
second
=
str
.
find
(
'\n'
,
fromPosition
);
if
(
bounds
.
second
==
string
::
npos
)
if
(
bounds
.
second
==
-
1
)
bounds
.
second
=
str
.
size
();
bounds
.
second
=
str
.
size
();
return
bounds
;
return
bounds
;
}
}
...
@@ -405,7 +405,7 @@ unsigned int Parser::_countTokens(unsigned int leftBound, unsigned int rightBoun
...
@@ -405,7 +405,7 @@ unsigned int Parser::_countTokens(unsigned int leftBound, unsigned int rightBoun
while
(
position
<
rightBount
)
while
(
position
<
rightBount
)
{
{
position
=
_fileContent
.
find_first_of
(
WHITESPACES
,
position
);
position
=
_fileContent
.
find_first_of
(
WHITESPACES
,
position
);
if
(
position
!=
string
::
npos
)
if
(
position
!=
-
1
)
++
tokensCount
;
++
tokensCount
;
//start search from next symbol
//start search from next symbol
++
position
;
++
position
;
...
@@ -416,7 +416,7 @@ unsigned int Parser::_countTokens(unsigned int leftBound, unsigned int rightBoun
...
@@ -416,7 +416,7 @@ unsigned int Parser::_countTokens(unsigned int leftBound, unsigned int rightBoun
unsigned
int
Parser
::
_skipWhiteSpaces
(
const
std
::
string
&
str
,
unsigned
int
fromPosition
)
unsigned
int
Parser
::
_skipWhiteSpaces
(
const
std
::
string
&
str
,
unsigned
int
fromPosition
)
{
{
unsigned
int
position
=
fromPosition
;
unsigned
int
position
=
fromPosition
;
if
(
WHITESPACES
.
find
(
str
[
0
])
!=
string
::
npos
)
if
(
WHITESPACES
.
find
(
str
[
0
])
!=
-
1
)
position
=
str
.
find_first_not_of
(
WHITESPACES
,
position
);
position
=
str
.
find_first_not_of
(
WHITESPACES
,
position
);
return
position
;
return
position
;
}
}
...
@@ -424,7 +424,7 @@ unsigned int Parser::_skipWhiteSpaces(const std::string & str, unsigned int from
...
@@ -424,7 +424,7 @@ unsigned int Parser::_skipWhiteSpaces(const std::string & str, unsigned int from
unsigned
int
Parser
::
_skipWhiteSpacesFromContent
(
unsigned
int
fromPosition
)
unsigned
int
Parser
::
_skipWhiteSpacesFromContent
(
unsigned
int
fromPosition
)
{
{
unsigned
int
position
=
fromPosition
;
unsigned
int
position
=
fromPosition
;
if
(
WHITESPACES
.
find
(
_fileContent
[
position
])
!=
string
::
npos
)
if
(
WHITESPACES
.
find
(
_fileContent
[
position
])
!=
-
1
)
position
=
_fileContent
.
find_first_not_of
(
WHITESPACES
,
position
);
// + 1;
position
=
_fileContent
.
find_first_not_of
(
WHITESPACES
,
position
);
// + 1;
return
position
;
return
position
;
...
@@ -453,7 +453,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
...
@@ -453,7 +453,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
static
std
::
string
objectContent
;
static
std
::
string
objectContent
;
size_t
contentStart
=
_fileContent
.
find_first_not_of
(
Parser
::
WHITESPACES
,
currentPosition
);
size_t
contentStart
=
_fileContent
.
find_first_not_of
(
Parser
::
WHITESPACES
,
currentPosition
);
if
(
contentStart
==
std
::
string
::
npos
)
if
(
contentStart
==
-
1
)
{
{
std
::
stringstream
strOut
;
std
::
stringstream
strOut
;
strOut
<<
"Wrong object "
<<
objectNumber
<<
"in PDF, cannot find content for it
\n
"
;
strOut
<<
"Wrong object "
<<
objectNumber
<<
"in PDF, cannot find content for it
\n
"
;
...
@@ -461,13 +461,13 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
...
@@ -461,13 +461,13 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
}
}
currentPosition
=
contentStart
;
currentPosition
=
contentStart
;
unsigned
int
endOfContent
=
_fileContent
.
find
(
"endobj"
,
contentStart
);
unsigned
int
endOfContent
=
_fileContent
.
find
(
"endobj"
,
contentStart
);
if
(
endOfContent
==
std
::
string
::
npos
)
if
(
endOfContent
==
-
1
)
{
{
stringstream
errorMessage
(
"Corrupted PDF file, obj does not have matching endobj"
);
stringstream
errorMessage
(
"Corrupted PDF file, obj does not have matching endobj"
);
throw
Exception
(
errorMessage
);
throw
Exception
(
errorMessage
);
}
}
unsigned
int
endOfStream
=
_fileContent
.
find
(
"endstream"
,
currentPosition
);
unsigned
int
endOfStream
=
_fileContent
.
find
(
"endstream"
,
currentPosition
);
if
((
endOfStream
!=
std
::
string
::
npos
)
&&
(
endOfStream
<
endOfContent
))
if
((
endOfStream
!=
-
1
)
&&
(
endOfStream
<
endOfContent
))
{
{
std
::
string
stream
(
"stream"
);
std
::
string
stream
(
"stream"
);
unsigned
int
beginOfStream
=
_fileContent
.
find
(
stream
,
currentPosition
)
+
stream
.
size
();
unsigned
int
beginOfStream
=
_fileContent
.
find
(
stream
,
currentPosition
)
+
stream
.
size
();
...
@@ -484,7 +484,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
...
@@ -484,7 +484,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
// try to use Length field to determine end of stream.
// try to use Length field to determine end of stream.
std
::
string
lengthToken
=
"/Length"
;
std
::
string
lengthToken
=
"/Length"
;
size_t
lengthBegin
=
Parser
::
findTokenName
(
_fileContent
,
lengthToken
,
contentStart
);
size_t
lengthBegin
=
Parser
::
findTokenName
(
_fileContent
,
lengthToken
,
contentStart
);
if
(
lengthBegin
!=
std
::
string
::
npos
)
if
(
lengthBegin
!=
-
1
)
{
{
std
::
string
lengthStr
;
std
::
string
lengthStr
;
size_t
lenPos
=
lengthBegin
+
lengthToken
.
size
();
size_t
lenPos
=
lengthBegin
+
lengthToken
.
size
();
...
@@ -512,7 +512,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
...
@@ -512,7 +512,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig
strin
>>
streamEnd
;
strin
>>
streamEnd
;
streamEnd
+=
beginOfStream
;
streamEnd
+=
beginOfStream
;
unsigned
int
streamEndBegin
=
_fileContent
.
find
(
"endstream"
,
streamEnd
);
unsigned
int
streamEndBegin
=
_fileContent
.
find
(
"endstream"
,
streamEnd
);
if
(
streamEndBegin
!=
std
::
string
::
npos
)
if
(
streamEndBegin
!=
-
1
)
{
{
endOfStream
=
streamEndBegin
;
endOfStream
=
streamEndBegin
;
}
}
...
@@ -537,18 +537,18 @@ unsigned int Parser::_readTrailerAndReturnRoot()
...
@@ -537,18 +537,18 @@ unsigned int Parser::_readTrailerAndReturnRoot()
unsigned
int
startOfTrailer
=
Parser
::
findToken
(
_fileContent
,
"trailer"
,
_getStartOfXrefWithRoot
());
unsigned
int
startOfTrailer
=
Parser
::
findToken
(
_fileContent
,
"trailer"
,
_getStartOfXrefWithRoot
());
std
::
string
rootStr
(
"/Root"
);
std
::
string
rootStr
(
"/Root"
);
unsigned
int
startOfRoot
=
Parser
::
findToken
(
_fileContent
,
rootStr
.
data
(),
startOfTrailer
);
unsigned
int
startOfRoot
=
Parser
::
findToken
(
_fileContent
,
rootStr
.
data
(),
startOfTrailer
);
if
(
startOfRoot
==
std
::
string
::
npos
)
if
(
startOfRoot
==
-
1
)
{
{
throw
Exception
(
"Cannot find Root object !"
);
throw
Exception
(
"Cannot find Root object !"
);
}
}
std
::
string
encryptStr
(
"/Encrypt"
);
std
::
string
encryptStr
(
"/Encrypt"
);
if
(
Parser
::
findToken
(
_fileContent
,
encryptStr
,
startOfTrailer
)
!=
std
::
string
::
npos
)
if
(
Parser
::
findToken
(
_fileContent
,
encryptStr
,
startOfTrailer
)
!=
-
1
)
{
{
throw
Exception
(
"Encrypted PDF is not supported!"
);
throw
Exception
(
"Encrypted PDF is not supported!"
);
}
}
startOfRoot
+=
rootStr
.
size
()
+
1
;
//"/Root + ' '
startOfRoot
+=
rootStr
.
size
()
+
1
;
//"/Root + ' '
unsigned
int
endOfRoot
=
startOfRoot
;
unsigned
int
endOfRoot
=
startOfRoot
;
while
(
NUMBERS
.
find
(
_fileContent
[
endOfRoot
++
])
!=
string
::
npos
)
while
(
NUMBERS
.
find
(
_fileContent
[
endOfRoot
++
])
!=
-
1
)
{}
{}
--
endOfRoot
;
--
endOfRoot
;
return
Utils
::
stringToInt
(
_fileContent
.
substr
(
startOfRoot
,
endOfRoot
-
startOfRoot
));
return
Utils
::
stringToInt
(
_fileContent
.
substr
(
startOfRoot
,
endOfRoot
-
startOfRoot
));
...
@@ -557,21 +557,21 @@ unsigned int Parser::_readTrailerAndReturnRoot()
...
@@ -557,21 +557,21 @@ unsigned int Parser::_readTrailerAndReturnRoot()
unsigned
int
Parser
::
_readTrailerAndRterievePrev
(
const
unsigned
int
startPositionForSearch
,
unsigned
int
&
previosXref
)
unsigned
int
Parser
::
_readTrailerAndRterievePrev
(
const
unsigned
int
startPositionForSearch
,
unsigned
int
&
previosXref
)
{
{
unsigned
int
startOfTrailer
=
Parser
::
findToken
(
_fileContent
,
"trailer"
,
startPositionForSearch
);
unsigned
int
startOfTrailer
=
Parser
::
findToken
(
_fileContent
,
"trailer"
,
startPositionForSearch
);
if
(
startOfTrailer
==
std
::
string
::
npos
)
if
(
startOfTrailer
==
-
1
)
{
{
throw
Exception
(
"Cannot find trailer!"
);
throw
Exception
(
"Cannot find trailer!"
);
}
}
unsigned
int
startOfPrev
=
_fileContent
.
find
(
"Prev "
,
startOfTrailer
);
unsigned
int
startOfPrev
=
_fileContent
.
find
(
"Prev "
,
startOfTrailer
);
unsigned
int
startxref
=
_fileContent
.
find
(
"startxref"
,
startOfTrailer
);
unsigned
int
startxref
=
_fileContent
.
find
(
"startxref"
,
startOfTrailer
);
if
(
startOfPrev
==
string
::
npos
||
(
startOfPrev
>
startxref
))
if
(
startOfPrev
==
-
1
||
(
startOfPrev
>
startxref
))
return
false
;
return
false
;
//"Prev "s length = 5
//"Prev "s length = 5
else
else
startOfPrev
+=
5
;
startOfPrev
+=
5
;
unsigned
int
endOfPrev
=
startOfPrev
;
unsigned
int
endOfPrev
=
startOfPrev
;
while
(
NUMBERS
.
find
(
_fileContent
[
endOfPrev
++
])
!=
string
::
npos
)
while
(
NUMBERS
.
find
(
_fileContent
[
endOfPrev
++
])
!=
-
1
)
{}
{}
--
endOfPrev
;
--
endOfPrev
;
previosXref
=
Utils
::
stringToInt
(
_fileContent
.
substr
(
startOfPrev
,
endOfPrev
-
startOfPrev
));
previosXref
=
Utils
::
stringToInt
(
_fileContent
.
substr
(
startOfPrev
,
endOfPrev
-
startOfPrev
));
...
@@ -589,13 +589,13 @@ std::string Parser::getNextToken(const std::string &str, unsigned int &position
...
@@ -589,13 +589,13 @@ std::string Parser::getNextToken(const std::string &str, unsigned int &position
}
}
//skip first spaces
//skip first spaces
size_t
beg_pos
=
str
.
find_first_not_of
(
Parser
::
WHITESPACES
,
position
);
size_t
beg_pos
=
str
.
find_first_not_of
(
Parser
::
WHITESPACES
,
position
);
if
(
beg_pos
==
std
::
string
::
npos
)
if
(
beg_pos
==
-
1
)
{
{
// it is empty string!
// it is empty string!
return
""
;
return
""
;
}
}
size_t
end_pos
=
str
.
find_first_of
(
Parser
::
WHITESPACES_AND_DELIMETERS
,
beg_pos
);
size_t
end_pos
=
str
.
find_first_of
(
Parser
::
WHITESPACES_AND_DELIMETERS
,
beg_pos
);
if
(
end_pos
==
std
::
string
::
npos
)
if
(
end_pos
==
-
1
)
{
{
end_pos
=
str
.
size
();
end_pos
=
str
.
size
();
}
}
...
@@ -614,7 +614,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP
...
@@ -614,7 +614,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP
{
{
if
(
found
)
if
(
found
)
{
{
*
found
=
std
::
string
::
npos
;
*
found
=
-
1
;
}
}
//trace("position = %d",position);
//trace("position = %d",position);
if
(
nextPosition
>=
str
.
size
()
)
if
(
nextPosition
>=
str
.
size
()
)
...
@@ -623,7 +623,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP
...
@@ -623,7 +623,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP
}
}
//skip first spaces
//skip first spaces
size_t
beg_pos
=
str
.
find_first_not_of
(
Parser
::
WHITESPACES
,
nextPosition
);
size_t
beg_pos
=
str
.
find_first_not_of
(
Parser
::
WHITESPACES
,
nextPosition
);
if
(
beg_pos
==
std
::
string
::
npos
)
if
(
beg_pos
==
-
1
)
{
{
// it is empty string!
// it is empty string!
return
false
;
return
false
;
...
@@ -634,7 +634,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP
...
@@ -634,7 +634,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP
}
}
size_t
end_pos
=
str
.
find_first_of
(
Parser
::
WHITESPACES
,
beg_pos
);
size_t
end_pos
=
str
.
find_first_of
(
Parser
::
WHITESPACES
,
beg_pos
);
if
(
end_pos
==
std
::
string
::
npos
)
if
(
end_pos
==
-
1
)
{
{
end_pos
=
str
.
size
();
end_pos
=
str
.
size
();
}
}
...
@@ -656,8 +656,8 @@ void Parser::trim(std::string &str)
...
@@ -656,8 +656,8 @@ void Parser::trim(std::string &str)
{
{
std
::
string
::
size_type
pos1
=
str
.
find_first_not_of
(
WHITESPACES
);
std
::
string
::
size_type
pos1
=
str
.
find_first_not_of
(
WHITESPACES
);
std
::
string
::
size_type
pos2
=
str
.
find_last_not_of
(
WHITESPACES
);
std
::
string
::
size_type
pos2
=
str
.
find_last_not_of
(
WHITESPACES
);
str
=
str
.
substr
(
pos1
==
std
::
string
::
npos
?
0
:
pos1
,
str
=
str
.
substr
(
pos1
==
-
1
?
0
:
pos1
,
pos2
==
std
::
string
::
npos
?
str
.
length
()
-
1
:
pos2
-
pos1
+
1
);
pos2
==
-
1
?
str
.
length
()
-
1
:
pos2
-
pos1
+
1
);
}
}
// Method tries to find the PDF token from the content
// Method tries to find the PDF token from the content
...
@@ -665,7 +665,7 @@ void Parser::trim(std::string &str)
...
@@ -665,7 +665,7 @@ void Parser::trim(std::string &str)
std
::
string
Parser
::
findTokenStr
(
const
std
::
string
&
content
,
const
std
::
string
&
pattern
,
size_t
start
,
size_t
&
foundStart
,
size_t
&
foundEnd
)
std
::
string
Parser
::
findTokenStr
(
const
std
::
string
&
content
,
const
std
::
string
&
pattern
,
size_t
start
,
size_t
&
foundStart
,
size_t
&
foundEnd
)
{
{
size_t
cur_pos
=
Parser
::
findToken
(
content
,
pattern
,
start
);
size_t
cur_pos
=
Parser
::
findToken
(
content
,
pattern
,
start
);
if
(
cur_pos
==
std
::
string
::
npos
)
if
(
cur_pos
==
-
1
)
{
{
return
""
;
return
""
;
}
}
...
@@ -673,7 +673,7 @@ std::string Parser::findTokenStr(const std::string &content, const std::string &
...
@@ -673,7 +673,7 @@ std::string Parser::findTokenStr(const std::string &content, const std::string &
cur_pos
+=
pattern
.
size
();
cur_pos
+=
pattern
.
size
();
// then lets parse the content of remaining part
// then lets parse the content of remaining part
size_t
end_pos
=
content
.
find_first_of
(
Parser
::
DELIMETERS
,
cur_pos
);
size_t
end_pos
=
content
.
find_first_of
(
Parser
::
DELIMETERS
,
cur_pos
);
if
(
end_pos
==
std
::
string
::
npos
)
if
(
end_pos
==
-
1
)
{
{
end_pos
=
content
.
size
();
end_pos
=
content
.
size
();
}
}
...
@@ -692,12 +692,12 @@ size_t Parser::findToken(const std::string &content, const std::string &keyword,
...
@@ -692,12 +692,12 @@ size_t Parser::findToken(const std::string &content, const std::string &keyword,
{
{
size_t
cur_pos
=
start
;
size_t
cur_pos
=
start
;
// lets find pattern first
// lets find pattern first
size_t
foundStart
=
std
::
string
::
npos
;
size_t
foundStart
=
-
1
;
size_t
savedPos
=
0
;
size_t
savedPos
=
0
;
while
(
1
)
while
(
1
)
{
{
cur_pos
=
content
.
find
(
keyword
,
cur_pos
);
cur_pos
=
content
.
find
(
keyword
,
cur_pos
);
if
(
cur_pos
==
std
::
string
::
npos
)
if
(
cur_pos
==
-
1
)
{
{
break
;
break
;
}
}
...
@@ -705,8 +705,8 @@ size_t Parser::findToken(const std::string &content, const std::string &keyword,
...
@@ -705,8 +705,8 @@ size_t Parser::findToken(const std::string &content, const std::string &keyword,
cur_pos
+=
keyword
.
size
();
cur_pos
+=
keyword
.
size
();
if
(
cur_pos
<
content
.
size
()
)
if
(
cur_pos
<
content
.
size
()
)
{
{
if
(
Parser
::
WHITESPACES
.
find
(
content
[
cur_pos
])
!=
std
::
string
::
npos
||
if
(
Parser
::
WHITESPACES
.
find
(
content
[
cur_pos
])
!=
-
1
||
Parser
::
DELIMETERS
.
find
(
content
[
cur_pos
])
!=
std
::
string
::
npos
)
Parser
::
DELIMETERS
.
find
(
content
[
cur_pos
])
!=
-
1
)
{
{
foundStart
=
savedPos
;
foundStart
=
savedPos
;
break
;
break
;
...
@@ -736,10 +736,10 @@ bool Parser::tokenIsAName(const std::string &content, size_t start )
...
@@ -736,10 +736,10 @@ bool Parser::tokenIsAName(const std::string &content, size_t start )
size_t
foundNonWhite
=
content
.
find_first_not_of
(
Parser
::
WHITESPACES
,
start
);
size_t
foundNonWhite
=
content
.
find_first_not_of
(
Parser
::
WHITESPACES
,
start
);
size_t
foundDelim
=
content
.
find_first_of
(
Parser
::
DELIMETERS
,
start
);
size_t
foundDelim
=
content
.
find_first_of
(
Parser
::
DELIMETERS
,
start
);
if
(
foundNonWhite
!=
std
::
string
::
npos
&&
if
(
foundNonWhite
!=
-
1
&&
foundDelim
!=
std
::
string
::
npos
)
foundDelim
!=
-
1
)
{
{
if
(
(
foundNonWhite
<
foundDelim
)
||
(
openBraces
.
find
(
content
[
foundDelim
])
!=
std
::
string
::
npos
)
)
if
(
(
foundNonWhite
<
foundDelim
)
||
(
openBraces
.
find
(
content
[
foundDelim
])
!=
-
1
)
)
{
{
if
(
found
)
if
(
found
)
{
{
...
@@ -778,13 +778,13 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw
...
@@ -778,13 +778,13 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw
{
{
size_t
cur_pos
=
start
;
size_t
cur_pos
=
start
;
// lets find pattern first
// lets find pattern first
size_t
foundStart
=
std
::
string
::
npos
;
size_t
foundStart
=
-
1
;
size_t
savedPos
=
0
;
size_t
savedPos
=
0
;
std
::
string
braces
=
"<[({"
;
std
::
string
braces
=
"<[({"
;
while
(
1
)
while
(
1
)
{
{
cur_pos
=
content
.
find
(
keyword
,
cur_pos
);
cur_pos
=
content
.
find
(
keyword
,
cur_pos
);
if
(
cur_pos
==
std
::
string
::
npos
)
if
(
cur_pos
==
-
1
)
{
{
break
;
break
;
}
}
...
@@ -792,7 +792,7 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw
...
@@ -792,7 +792,7 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw
cur_pos
+=
keyword
.
size
();
cur_pos
+=
keyword
.
size
();
if
(
cur_pos
<
content
.
size
()
)
if
(
cur_pos
<
content
.
size
()
)
{
{
if
(
Parser
::
WHITESPACES_AND_DELIMETERS
.
find
(
content
[
cur_pos
])
!=
std
::
string
::
npos
)
if
(
Parser
::
WHITESPACES_AND_DELIMETERS
.
find
(
content
[
cur_pos
])
!=
-
1
)
{
{
if
(
tokenIsAName
(
content
,
cur_pos
)
)
if
(
tokenIsAName
(
content
,
cur_pos
)
)
{
{
...
@@ -813,7 +813,7 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw
...
@@ -813,7 +813,7 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw
unsigned
int
Parser
::
findEndOfElementContent
(
const
std
::
string
&
content
,
unsigned
int
startOfPageElement
)
unsigned
int
Parser
::
findEndOfElementContent
(
const
std
::
string
&
content
,
unsigned
int
startOfPageElement
)
{
{
unsigned
int
foundEnd
=
std
::
string
::
npos
;
unsigned
int
foundEnd
=
-
1
;
std
::
stack
<
std
::
string
>
delimStack
;
std
::
stack
<
std
::
string
>
delimStack
;
std
::
string
endDelim
=
"/]>)}"
;
std
::
string
endDelim
=
"/]>)}"
;
unsigned
int
curPos
=
startOfPageElement
;
unsigned
int
curPos
=
startOfPageElement
;
...
@@ -832,7 +832,7 @@ unsigned int Parser::findEndOfElementContent(const std::string &content,unsigned
...
@@ -832,7 +832,7 @@ unsigned int Parser::findEndOfElementContent(const std::string &content,unsigned
unsigned
int
foundOpenBrace
=
content
.
find
(
"["
,
curPos
);
unsigned
int
foundOpenBrace
=
content
.
find
(
"["
,
curPos
);
unsigned
int
foundOpenDict
=
content
.
find
(
"<"
,
curPos
);
unsigned
int
foundOpenDict
=
content
.
find
(
"<"
,
curPos
);
if
(
foundDelimeter
==
std
::
string
::
npos
&&
foundOpenBrace
==
std
::
string
::
npos
&&
foundOpenDict
==
std
::
string
::
npos
)
if
(
foundDelimeter
==
-
1
&&
foundOpenBrace
==
-
1
&&
foundOpenDict
==
-
1
)
{
{
if
(
!
delimStack
.
empty
()
)
if
(
!
delimStack
.
empty
()
)
{
{
...
@@ -882,7 +882,7 @@ unsigned int Parser::findEndOfElementContent(const std::string &content,unsigned
...
@@ -882,7 +882,7 @@ unsigned int Parser::findEndOfElementContent(const std::string &content,unsigned
if
(
delimStack
.
empty
()
)
if
(
delimStack
.
empty
()
)
{
{
foundEnd
=
content
.
find_first_of
(
delimeter
,
curPos
);
foundEnd
=
content
.
find_first_of
(
delimeter
,
curPos
);
if
(
foundEnd
==
std
::
string
::
npos
)
if
(
foundEnd
==
-
1
)
{
{
foundEnd
=
curPos
;
foundEnd
=
curPos
;
}
}
...
...
src/pdf-merger/Rectangle.cpp
View file @
aa6a893a
...
@@ -42,14 +42,14 @@ y2(0)
...
@@ -42,14 +42,14 @@ y2(0)
{
{
unsigned
int
rectanglePosition
=
Parser
::
findToken
(
content
,
rectangleName
);
unsigned
int
rectanglePosition
=
Parser
::
findToken
(
content
,
rectangleName
);
if
(
rectanglePosition
==
std
::
string
::
npos
)
if
(
rectanglePosition
==
-
1
)
{
{
std
::
cerr
<<
"Unable to find rectangle name "
<<
rectangleName
<<
" in content
\n
"
;
std
::
cerr
<<
"Unable to find rectangle name "
<<
rectangleName
<<
" in content
\n
"
;
}
}
size_t
beg
=
content
.
find
(
"["
,
rectanglePosition
);
size_t
beg
=
content
.
find
(
"["
,
rectanglePosition
);
size_t
end
=
content
.
find
(
"]"
,
rectanglePosition
);
size_t
end
=
content
.
find
(
"]"
,
rectanglePosition
);
if
(
beg
!=
std
::
string
::
npos
&&
end
!=
std
::
string
::
npos
)
if
(
beg
!=
-
1
&&
end
!=
-
1
)
{
{
std
::
string
arr
=
content
.
substr
(
beg
+
1
,
end
-
beg
-
1
);
std
::
string
arr
=
content
.
substr
(
beg
+
1
,
end
-
beg
-
1
);
std
::
stringstream
in
;
std
::
stringstream
in
;
...
@@ -119,7 +119,7 @@ void Rectangle::updateRectangle(Object * objectWithRectangle, const char * delim
...
@@ -119,7 +119,7 @@ void Rectangle::updateRectangle(Object * objectWithRectangle, const char * delim
std
::
string
objectContent
=
objectWithMatrix
->
getObjectContent
();
std
::
string
objectContent
=
objectWithMatrix
->
getObjectContent
();
unsigned
int
matrixPosition
=
Parser
::
findToken
(
objectContent
,
"/Matrix"
);
unsigned
int
matrixPosition
=
Parser
::
findToken
(
objectContent
,
"/Matrix"
);
if
(
matrixPosition
==
std
::
string
::
npos
)
if
(
matrixPosition
==
-
1
)
continue
;
continue
;
unsigned
int
matrixValueLeftBound
=
objectContent
.
find
(
"["
,
matrixPosition
);
unsigned
int
matrixValueLeftBound
=
objectContent
.
find
(
"["
,
matrixPosition
);
unsigned
int
matrixValueRightBound
=
objectContent
.
find
(
"]"
,
matrixValueLeftBound
)
+
1
;
unsigned
int
matrixValueRightBound
=
objectContent
.
find
(
"]"
,
matrixValueLeftBound
)
+
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment