Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Okular
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joao Oliveira
Okular
Commits
c7432cda
Commit
c7432cda
authored
Jul 27, 2019
by
Joao Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented support for AFSpecial_Format and AFSpecial_Keystroke
parent
052662d7
Pipeline
#6514
passed with stage
in 17 minutes and 16 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
0 deletions
+164
-0
autotests/CMakeLists.txt
autotests/CMakeLists.txt
+1
-0
autotests/formattest.cpp
autotests/formattest.cpp
+74
-0
core/script/builtin.js
core/script/builtin.js
+89
-0
No files found.
autotests/CMakeLists.txt
View file @
c7432cda
...
...
@@ -22,6 +22,7 @@ if(Poppler_Qt5_FOUND)
TEST_NAME
"kjsfunctionstest"
LINK_LIBRARIES Qt5::Widgets Qt5::Test okularcore
)
ecm_add_test
(
formattest.cpp
TEST_NAME
"formattest"
LINK_LIBRARIES Qt5::Widgets Qt5::Test okularcore
...
...
autotests/formattest.cpp
View file @
c7432cda
...
...
@@ -28,6 +28,7 @@ private slots:
void
initTestCase
();
void
cleanupTestCase
();
void
testTimeFormat
();
void
testSpecialFormat
();
private:
Okular
::
Document
*
m_document
;
...
...
@@ -135,6 +136,79 @@ void FormatTest::testTimeFormat()
QCOMPARE
(
QStringLiteral
(
"1:20:00 pm"
),
m_formattedText
);
}
void
FormatTest
::
testSpecialFormat
()
{
Okular
::
FormFieldText
*
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"CEP"
)
]
);
// This field will just become itself, so we test only if keystroke worked.
fft
->
setText
(
QStringLiteral
(
"12345"
)
);
bool
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
QCOMPARE
(
true
,
ok
);
fft
->
setText
(
QStringLiteral
(
"123456"
)
);
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
false
,
ok
);
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"8Digits"
)
]
);
fft
->
setText
(
QStringLiteral
(
"123456789"
)
);
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
true
,
ok
);
QCOMPARE
(
m_formattedText
,
QStringLiteral
(
"12345-6789"
)
);
fft
->
setText
(
QStringLiteral
(
"1234567890"
)
);
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
false
,
ok
);
QCOMPARE
(
m_formattedText
,
QStringLiteral
(
"12345-6789"
)
);
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"telefone"
)
]
);
fft
->
setText
(
QStringLiteral
(
"1234567890"
)
);
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
true
,
ok
);
QCOMPARE
(
m_formattedText
,
QStringLiteral
(
"(123) 456-7890"
)
);
fft
->
setText
(
QStringLiteral
(
"12345678900"
)
);
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
false
,
ok
);
QCOMPARE
(
m_formattedText
,
QStringLiteral
(
"(123) 456-7890"
)
);
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"CPF"
)
]
);
fft
->
setText
(
QStringLiteral
(
"123456789"
)
);
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
true
,
ok
);
QCOMPARE
(
m_formattedText
,
QStringLiteral
(
"123-45-6789"
)
);
fft
->
setText
(
QStringLiteral
(
"1234567890"
)
);
ok
=
false
;
m_document
->
processKeystrokeAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FieldModified
),
fft
,
ok
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
false
,
ok
);
QCOMPARE
(
m_formattedText
,
QStringLiteral
(
"123-45-6789"
)
);
}
void
FormatTest
::
cleanupTestCase
()
{
m_document
->
closeDocument
();
...
...
core/script/builtin.js
View file @
c7432cda
...
...
@@ -156,3 +156,92 @@ function AFTime_Keystroke( ptf )
{
return
;
}
/** AFSpecial_Format
* psf is the type of formatting to use:
* 0 = zip code
* 1 = zip + 4
* 2 = phone
* 3 = SSN
*
* These are all in the US format.
*/
function
AFSpecial_Format
(
psf
)
{
if
(
!
event
.
value
||
psf
==
0
)
{
return
;
}
var
ret
=
event
.
value
;
if
(
psf
===
1
)
ret
=
ret
.
substr
(
0
,
5
)
+
'
-
'
+
ret
.
substr
(
5
,
4
);
else
if
(
psf
===
2
)
ret
=
'
(
'
+
ret
.
substr
(
0
,
3
)
+
'
)
'
+
ret
.
substr
(
3
,
3
)
+
'
-
'
+
ret
.
substr
(
6
,
4
);
else
if
(
psf
===
3
)
ret
=
ret
.
substr
(
0
,
3
)
+
'
-
'
+
ret
.
substr
(
3
,
2
)
+
'
-
'
+
ret
.
substr
(
5
,
4
);
event
.
value
=
ret
;
}
/** AFSpecial_Keystroke
*
* Checks if the String in event.value is valid.
*
* Parameter description based on Acrobat Help:
*
* psf is the type of formatting to use:
* 0 = zip code
* 1 = zip + 4
* 2 = phone
* 3 = SSN
*
* These are all in the US format. We check to see if only numbers are inserted and the length of the string.
*/
function
AFSpecial_Keystroke
(
psf
)
{
if
(
!
event
.
value
)
{
return
;
}
var
str
=
event
.
value
;
if
(
psf
===
0
)
{
if
(
str
.
length
>
5
)
{
event
.
rc
=
false
;
return
;
}
}
else
if
(
psf
===
1
||
psf
===
3
)
{
if
(
str
.
length
>
9
)
{
event
.
rc
=
false
;
return
;
}
}
else
if
(
psf
===
2
)
{
if
(
str
.
length
>
10
)
{
event
.
rc
=
false
;
return
;
}
}
for
(
i
=
0
;
i
<
str
.
length
;
++
i
)
{
if
(
!
(
str
[
i
]
<=
'
9
'
&&
str
[
i
]
>=
'
0
'
)
)
{
event
.
rc
=
false
;
return
;
}
}
}
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