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
052662d7
Commit
052662d7
authored
Jul 27, 2019
by
Joao Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented support for AFTime_Format and AFTime_Keystroke
parent
bf7a53d6
Pipeline
#6515
passed with stage
in 10 minutes and 33 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
246 additions
and
0 deletions
+246
-0
autotests/CMakeLists.txt
autotests/CMakeLists.txt
+4
-0
autotests/data/formattest.pdf
autotests/data/formattest.pdf
+0
-0
autotests/formattest.cpp
autotests/formattest.cpp
+146
-0
core/script/builtin.js
core/script/builtin.js
+96
-0
No files found.
autotests/CMakeLists.txt
View file @
052662d7
...
...
@@ -22,6 +22,10 @@ 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
)
endif
()
ecm_add_test
(
documenttest.cpp
...
...
autotests/data/formattest.pdf
0 → 100644
View file @
052662d7
File added
autotests/formattest.cpp
0 → 100644
View file @
052662d7
/***************************************************************************
* Copyright (C) 2019 by João Netto <joaonetto901@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <QtTest>
#include <QMap>
#include <QMimeType>
#include <QMimeDatabase>
#include "../settings_core.h"
#include <core/document.h>
#include <core/page.h>
#include <core/form.h>
#include <QLocale>
#include "../generators/poppler/config-okular-poppler.h"
class
FormatTest
:
public
QObject
{
Q_OBJECT
private
slots
:
void
initTestCase
();
void
cleanupTestCase
();
void
testTimeFormat
();
private:
Okular
::
Document
*
m_document
;
QMap
<
QString
,
Okular
::
FormField
*>
m_fields
;
QString
m_formattedText
;
};
void
FormatTest
::
initTestCase
()
{
Okular
::
SettingsCore
::
instance
(
QStringLiteral
(
"formattest"
)
);
m_document
=
new
Okular
::
Document
(
nullptr
);
const
QString
testFile
=
QStringLiteral
(
KDESRCDIR
"data/formattest.pdf"
);
QMimeDatabase
db
;
const
QMimeType
mime
=
db
.
mimeTypeForFile
(
testFile
);
QCOMPARE
(
m_document
->
openDocument
(
testFile
,
QUrl
(),
mime
),
Okular
::
Document
::
OpenSuccess
);
connect
(
m_document
,
&
Okular
::
Document
::
refreshFormWidget
,
[
=
](
Okular
::
FormField
*
form
)
{
Okular
::
FormFieldText
*
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
form
);
if
(
fft
)
m_formattedText
=
fft
->
text
();
});
const
Okular
::
Page
*
page
=
m_document
->
page
(
0
);
for
(
Okular
::
FormField
*
ff
:
page
->
formFields
()
)
{
m_fields
.
insert
(
ff
->
name
(),
ff
);
}
}
void
FormatTest
::
testTimeFormat
()
{
Okular
::
FormFieldText
*
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"time1"
)
]
);
fft
->
setText
(
QStringLiteral
(
"1:20"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"01:20"
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"1:20 pm"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"13:20"
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"1"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
""
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"25:12"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
""
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"abcd"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
""
),
m_formattedText
);
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"time2"
)
]
);
fft
->
setText
(
QStringLiteral
(
"1:20"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"1:20 am"
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"01:20 pm"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"1:20 pm"
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"13:20"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"1:20 pm"
),
m_formattedText
);
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"time3"
)
]
);
fft
->
setText
(
QStringLiteral
(
"1:20"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"01:20:00"
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"1:20:00 pm"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"13:20:00"
),
m_formattedText
);
fft
=
reinterpret_cast
<
Okular
::
FormFieldText
*
>
(
m_fields
[
QStringLiteral
(
"time4"
)
]
);
fft
->
setText
(
QStringLiteral
(
"1:20:00"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"1:20:00 am"
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"01:20:00 pm"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"1:20:00 pm"
),
m_formattedText
);
fft
->
setText
(
QStringLiteral
(
"13:20:00"
)
);
m_document
->
processFormatAction
(
fft
->
additionalAction
(
Okular
::
FormField
::
FormatField
),
fft
);
QCOMPARE
(
QStringLiteral
(
"1:20:00 pm"
),
m_formattedText
);
}
void
FormatTest
::
cleanupTestCase
()
{
m_document
->
closeDocument
();
delete
m_document
;
}
QTEST_MAIN
(
FormatTest
)
#include "formattest.moc"
core/script/builtin.js
View file @
052662d7
...
...
@@ -60,3 +60,99 @@ function AFSimple_Calculate( cFunction, cFields )
event
.
value
=
ret
;
}
/** AFTime_Format
*
* Formats event.value based on parameters.
*
* Parameter description based on Acrobat Help:
*
* ptf is the number which should be used to format the time, is one of:
* 0 = 24HR_MM [ 14:30 ]
* 1 = 12HR_MM [ 2:30 PM ]
* 2 = 24HR_MM_SS [ 14:30:15 ]
* 3 = 12HR_MM_SS [ 2:30:15 PM ]
*/
function
AFTime_Format
(
ptf
)
{
if
(
!
event
.
value
)
{
return
;
}
var
tokens
=
event
.
value
.
split
(
/
\D
/
);
var
invalidDate
=
false
;
// Remove empty elements of the array
tokens
=
tokens
.
filter
(
Boolean
);
if
(
tokens
.
length
<
2
)
invalidDate
=
true
;
// Check if every number is valid
for
(
i
=
0
;
i
<
tokens
.
length
;
++
i
)
{
if
(
isNaN
(
tokens
[
i
]
)
)
{
invalidDate
=
true
;
break
;
}
switch
(
i
)
{
case
0
:
{
if
(
tokens
[
i
]
>
23
||
tokens
[
i
]
<
0
)
invalidDate
=
true
;
break
;
}
case
1
:
case
2
:
{
if
(
tokens
[
i
]
>
59
||
tokens
[
i
]
<
0
)
invalidDate
=
true
;
break
;
}
}
}
if
(
invalidDate
)
{
event
.
value
=
""
;
return
;
}
// Make it of lenght 3, since we use hh, mm, ss
while
(
tokens
.
length
<
3
)
tokens
.
push
(
0
);
// Add 12 to time if it's PM and less than 12
if
(
(
event
.
value
.
search
(
'
PM
'
)
!==
-
1
||
event
.
value
.
search
(
'
pm
'
)
!==
-
1
)
&&
Number
(
tokens
[
0
]
)
<
12
)
tokens
[
0
]
=
Number
(
tokens
[
0
]
)
+
12
;
// We use a random date, because we only care about time.
var
date
=
new
Date
(
2019
,
7
,
12
,
tokens
[
0
],
tokens
[
1
],
tokens
[
2
]
);
var
ret
;
switch
(
ptf
)
{
case
0
:
ret
=
util
.
printd
(
"
hh:MM
"
,
date
);
break
;
case
1
:
ret
=
util
.
printd
(
"
h:MM ap
"
,
date
);
break
;
case
2
:
ret
=
util
.
printd
(
"
hh:MM:ss
"
,
date
);
break
;
case
3
:
ret
=
util
.
printd
(
"
h:MM:ss ap
"
,
date
);
break
;
}
event
.
value
=
ret
;
}
/** AFTime_Keystroke
*
* Checks if the string in event.value is valid. Not used.
*/
function
AFTime_Keystroke
(
ptf
)
{
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