Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 368f0d40
authored
Oct 23, 2013
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Insomnia cardtemplates.
1 parent
ce16315e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
50 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardPrintBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardPrintBean.java
View file @
368f0d4
...
@@ -129,11 +129,9 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -129,11 +129,9 @@ public class CardPrintBean implements CardPrintBeanLocal {
CardTemplate
cardTemplate
=
printedCard
.
getTemplate
();
CardTemplate
cardTemplate
=
printedCard
.
getTemplate
();
BufferedImage
cardBackground
=
ImageIO
.
read
(
new
ByteArrayInputStream
(
BufferedImage
cardBackground
=
ImageIO
.
read
(
new
ByteArrayInputStream
(
cardTemplate
.
getImage
()));
cardTemplate
.
getImage
()));
BufferedImage
faceBufferedImage
=
ImageIO
BufferedImage
faceBufferedImage
=
ImageIO
.
read
(
new
ByteArrayInputStream
(
user
.
getCurrentImage
().
getImageData
()));
.
read
(
new
ByteArrayInputStream
(
user
.
getCurrentImage
().
getImageData
()));
/*
/*
* if (faceBufferedImage.getWidth() > 1024 ||
* if (faceBufferedImage.getWidth() > 1024 ||
...
@@ -141,6 +139,7 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -141,6 +139,7 @@ public class CardPrintBean implements CardPrintBeanLocal {
* Exception("Image dimensions too large, please take/upload smaller!"
* Exception("Image dimensions too large, please take/upload smaller!"
* ); }
* ); }
*/
*/
// force image aspect ratio.
int
originalWidth
=
faceBufferedImage
.
getWidth
();
int
originalWidth
=
faceBufferedImage
.
getWidth
();
int
originalHeight
=
faceBufferedImage
.
getHeight
();
int
originalHeight
=
faceBufferedImage
.
getHeight
();
...
@@ -160,16 +159,14 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -160,16 +159,14 @@ public class CardPrintBean implements CardPrintBeanLocal {
Page
page
=
new
Page
(
pdf
,
new
float
[]
{
pagex
,
pagey
});
Page
page
=
new
Page
(
pdf
,
new
float
[]
{
pagex
,
pagey
});
// Render background image
// Render background image
Image
templateImage
=
new
Image
(
pdf
,
Image
templateImage
=
new
Image
(
pdf
,
convertBufferedImageToPng
(
cardBackground
),
ImageType
.
PNG
);
convertBufferedImageToPng
(
cardBackground
),
ImageType
.
PNG
);
templateImage
.
setPosition
(
0
,
0
);
templateImage
.
setPosition
(
0
,
0
);
templateImage
.
scaleBy
(
0.245
);
templateImage
.
scaleBy
(
0.245
);
templateImage
.
drawOn
(
page
);
templateImage
.
drawOn
(
page
);
// Render face image
// Render face image
Image
faceImage
=
new
Image
(
pdf
,
Image
faceImage
=
new
Image
(
pdf
,
convertBufferedImageToPng
(
faceBufferedImage
),
ImageType
.
PNG
);
convertBufferedImageToPng
(
faceBufferedImage
),
ImageType
.
PNG
);
faceImage
.
setPosition
(
55
,
75
);
faceImage
.
setPosition
(
15.5
,
67
);
//faceImage.setPosition(175, 222);
//faceImage.setPosition(175, 222);
// faceImage.scaleBy(0.32);
// faceImage.scaleBy(0.32);
faceImage
.
scaleBy
(((
410.0
*
0.245
)
/
faceImage
.
getHeight
()));
faceImage
.
scaleBy
(((
410.0
*
0.245
)
/
faceImage
.
getHeight
()));
...
@@ -178,14 +175,15 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -178,14 +175,15 @@ public class CardPrintBean implements CardPrintBeanLocal {
// Render texts
// Render texts
// Big font for nick
// Big font for nick
com
.
pdfjet
.
Font
nickFont
=
new
com
.
pdfjet
.
Font
(
pdf
,
CoreFont
.
HELVETICA
);
com
.
pdfjet
.
Font
nickFont
=
new
com
.
pdfjet
.
Font
(
pdf
,
CoreFont
.
HELVETICA
);
nickFont
.
setSize
(
1
6
.0
);
nickFont
.
setSize
(
1
7
.0
);
int
[]
white
=
new
int
[]
{
255
,
255
,
255
};
// User nick text
// User nick text
TextLine
nickTextLine
=
new
TextLine
(
nickFont
);
TextLine
nickTextLine
=
new
TextLine
(
nickFont
);
nickTextLine
.
setText
(
user
.
getUser
().
getNick
());
nickTextLine
.
setText
(
user
.
getUser
().
getNick
());
nickTextLine
.
setPosition
(
1
9.0
,
193
.0
);
nickTextLine
.
setPosition
(
1
7.0
,
195
.0
);
nickTextLine
.
setColor
(
new
int
[]
{
1
,
1
,
1
}
);
nickTextLine
.
setColor
(
white
);
nickTextLine
.
drawOn
(
page
);
nickTextLine
.
drawOn
(
page
);
// Smaller font
// Smaller font
...
@@ -193,19 +191,18 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -193,19 +191,18 @@ public class CardPrintBean implements CardPrintBeanLocal {
font
.
setSize
(
10.0
);
font
.
setSize
(
10.0
);
// Full name text
// Full name text
String
wholeName
=
user
.
getUser
().
getFirstnames
()
+
" "
String
wholeName
=
user
.
getUser
().
getFirstnames
()
+
" "
+
user
.
getUser
().
getLastname
();
+
user
.
getUser
().
getLastname
();
TextLine
wholeNameText
=
new
TextLine
(
font
);
TextLine
wholeNameText
=
new
TextLine
(
font
);
wholeNameText
.
setText
(
wholeName
);
wholeNameText
.
setText
(
wholeName
);
wholeNameText
.
setPosition
(
17.0
,
21
2
.0
);
wholeNameText
.
setPosition
(
17.0
,
21
1
.0
);
wholeNameText
.
setColor
(
new
int
[]
{
1
,
1
,
1
}
);
wholeNameText
.
setColor
(
white
);
wholeNameText
.
drawOn
(
page
);
wholeNameText
.
drawOn
(
page
);
// Role text
// Role text
TextLine
roleTextLine
=
new
TextLine
(
font
);
TextLine
roleTextLine
=
new
TextLine
(
font
);
roleTextLine
.
setText
(
cardTemplate
.
getName
());
roleTextLine
.
setText
(
cardTemplate
.
getName
());
roleTextLine
.
setPosition
(
17.0
,
22
3
.0
);
roleTextLine
.
setPosition
(
17.0
,
22
4
.0
);
roleTextLine
.
setColor
(
new
int
[]
{
1
,
1
,
1
}
);
roleTextLine
.
setColor
(
white
);
roleTextLine
.
drawOn
(
page
);
roleTextLine
.
drawOn
(
page
);
// Barcode
// Barcode
...
@@ -215,12 +212,13 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -215,12 +212,13 @@ public class CardPrintBean implements CardPrintBeanLocal {
// barcodeString = barcodeString.substring(barcodeString.length() -
// barcodeString = barcodeString.substring(barcodeString.length() -
// 12);
// 12);
BufferedImage
barCodeBufferedImage
=
ImageIO
.
read
(
barcodeBean
.
getCardBarcode
(
printedCard
));
// No barcode in insomnia..
Image
barCodeImage
=
new
Image
(
pdf
,
convertBufferedImageToPng
(
barCodeBufferedImage
),
ImageType
.
PNG
);
/* BufferedImage barCodeBufferedImage = ImageIO.read(barcodeBean.getCardBarcode(printedCard));
barCodeImage
.
setPosition
(
0.0
,
230
);
// 243.5);
Image barCodeImage = new Image(pdf, convertBufferedImageToPng(barCodeBufferedImage), ImageType.PNG);
barCodeImage
.
scaleBy
(
0.7
);
barCodeImage.setPosition(0.0, 230);// 243.5);
barCodeImage
.
drawOn
(
page
);
barCodeImage.scaleBy(0.7);
barCodeImage.drawOn(page);
*/
mpr
.
getAffectedUsers
().
add
(
user
);
mpr
.
getAffectedUsers
().
add
(
user
);
}
}
pdf
.
flush
();
pdf
.
flush
();
...
@@ -254,24 +252,27 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -254,24 +252,27 @@ public class CardPrintBean implements CardPrintBeanLocal {
g
.
drawImage
(
base
,
0
,
0
,
base
.
getWidth
(),
base
.
getHeight
(),
null
);
g
.
drawImage
(
base
,
0
,
0
,
base
.
getWidth
(),
base
.
getHeight
(),
null
);
// g.drawImage(face, AffineTransform.getScaleInstance(0.31, 0.31),
// g.drawImage(face, AffineTransform.getScaleInstance(0.31, 0.31),
// null);
// null);
g
.
drawImage
(
face
,
174
,
237
,
301
,
410
,
null
);
g
.
drawImage
(
face
,
250
,
300
,
301
,
410
,
null
);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
PLAIN
,
70
));
Font
nickfont
=
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
65
);
Font
font
=
new
Font
(
"Century gothic"
,
Font
.
PLAIN
,
70
);
Font
font
=
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
45
);
int
nickWidth
=
g
.
getFontMetrics
(
font
).
stringWidth
(
user
.
getUser
().
getNick
());
int
nickX
=
(
646
/
2
)
-
(
nickWidth
/
2
);
//int nickWidth = g.getFontMetrics(font).stringWidth(user.getUser().getNick());
int
nickY
=
750
;
//int nickX = (646 / 2) - (nickWidth / 2);
int
nickX
=
60
;
int
nickY
=
800
;
//Color transparentWhite = new Color(255, 255, 255, 140);
//Color transparentWhite = new Color(255, 255, 255, 140);
//g.setColor(transparentWhite);
//g.setColor(transparentWhite);
//g.fillRect(nickX - 20, nickY - 50, nickWidth + 40, 50);
//g.fillRect(nickX - 20, nickY - 50, nickWidth + 40, 50);
g
.
setColor
(
Color
.
black
);
g
.
setColor
(
Color
.
white
);
g
.
setFont
(
font
);
g
.
setFont
(
nick
font
);
g
.
drawString
(
user
.
getUser
().
getNick
(),
nickX
,
nickY
);
g
.
drawString
(
user
.
getUser
().
getNick
(),
nickX
,
nickY
);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
45
)
);
g
.
setFont
(
font
);
StringBuilder
wholeName
=
new
StringBuilder
();
StringBuilder
wholeName
=
new
StringBuilder
();
wholeName
.
append
(
user
.
getUser
().
getFirstnames
()).
append
(
" "
).
append
(
user
.
getUser
().
getLastname
());
wholeName
.
append
(
user
.
getUser
().
getFirstnames
()).
append
(
" "
).
append
(
user
.
getUser
().
getLastname
());
...
@@ -284,25 +285,26 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -284,25 +285,26 @@ public class CardPrintBean implements CardPrintBeanLocal {
// g.drawString(owner.getId().toString(), 60, 948);
// g.drawString(owner.getId().toString(), 60, 948);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
40
));
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
40
));
g
.
drawString
(
wholeName
.
toString
(),
60
,
950
);
g
.
drawString
(
wholeName
.
toString
(),
60
,
865
);
//
g.drawString(card.getTemplate().getName(), 60, 915);
g
.
drawString
(
card
.
getTemplate
().
getName
(),
60
,
915
);
PrintedCard
printedCard
=
cardTemplateBean
.
checkPrintedCard
(
user
);
//g.drawString(card.getTemplate().getName(), 60, 915);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
PLAIN
,
30
));
g
.
setColor
(
Color
.
white
);
BufferedImage
barCodeBufferedImage
=
null
;
if
(
printedCard
!=
null
)
{
int
barcodeX
=
(
base
.
getWidth
()
-
400
)
/
2
;
int
barcodeY
=
base
.
getHeight
()
-
50
;
g
.
drawString
(
barcodeBean
.
getVrAuthCodeForCard
(
printedCard
),
445
,
905
);
barCodeBufferedImage
=
ImageIO
.
read
(
barcodeBean
.
getCardBarcode
(
printedCard
));
g
.
drawImage
(
barCodeBufferedImage
,
barcodeX
,
barcodeY
,
400
,
barCodeBufferedImage
.
getHeight
(),
null
);
g
.
setColor
(
Color
.
white
);
}
//PrintedCard printedCard = cardTemplateBean.checkPrintedCard(user);
/* Ei insomniassa
g.setFont(new Font("Century gothic", Font.PLAIN, 30));
g.setColor(Color.white);
BufferedImage barCodeBufferedImage = null;
if (printedCard != null) {
int barcodeX = (base.getWidth() - 400) / 2;
int barcodeY = base.getHeight() - 50;
g.drawString(barcodeBean.getVrAuthCodeForCard(printedCard), 445, 905);
barCodeBufferedImage = ImageIO.read(barcodeBean.getCardBarcode(printedCard));
g.drawImage(barCodeBufferedImage, barcodeX, barcodeY, 400, barCodeBufferedImage.getHeight(), null);
g.setColor(Color.white);
}
*/
g
.
fillRect
(
0
,
base
.
getHeight
()
-
20
,
base
.
getWidth
(),
base
.
getHeight
());
g
.
fillRect
(
0
,
base
.
getHeight
()
-
20
,
base
.
getWidth
(),
base
.
getHeight
());
g
.
dispose
();
g
.
dispose
();
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment