slight refactoring of orientation handling

This commit is contained in:
knut 2008-03-24 17:32:00 +00:00
parent 03f58b7b5e
commit b5ab98668a
3 changed files with 18 additions and 25 deletions

View file

@ -30,25 +30,16 @@ public class Dimension {
public Dimension scaled(int max) { public Dimension scaled(int max) {
int sw, sh; return w > h ? scaleWidth(max) : scaleHeight(max);
if (w > h) {
if (w > max) {
sw = max;
sh = (max * h + max / 2) / w;
} else {
sw = w;
sh = h;
} }
} else {
if (h > max) {
sw = (max * w + max / 2) / h; public Dimension scaleWidth(int maxWidth) {
sh = max; return new Dimension(maxWidth, (maxWidth * h + maxWidth / 2) / w);
} else {
sw = w;
sh = h;
} }
}
return new Dimension(sw, sh); public Dimension scaleHeight(int maxHeight) {
return new Dimension((maxHeight * w + maxHeight / 2) / h, maxHeight);
} }

View file

@ -43,7 +43,7 @@ public class Entry {
* @return Returns the size. * @return Returns the size.
*/ */
public Dimension getSize() { public Dimension getSize() {
return size; return getOrientation() == 6 ? size.flip() : size;
} }

View file

@ -24,6 +24,12 @@
text-decoration: underline; text-decoration: underline;
color: #6a6a6a; color: #6a6a6a;
} }
div {
float: left;
}
img {
padding: 5px;
}
</style> </style>
</head> </head>
@ -32,12 +38,8 @@
<hr/> <hr/>
#set($thmb = 150) #set($thmb = 150)
#foreach($entry in $entries) #foreach($entry in $entries)
#if($entry.orientation == 6)
#set($dim = $entry.size.scaled($thmb).flip())
#else
#set($dim = $entry.size.scaled($thmb)) #set($dim = $entry.size.scaled($thmb))
#end <div class="home_entry_table" height="200">
<div class="home_entry_table">
<span class="name">$entry.name</span><br/> <span class="name">$entry.name</span><br/>
<a href="$entry.name"><img src="$entry.name?size=$thmb" border="0" width="$dim.width" height="$dim.height"/></a><br/> <a href="$entry.name"><img src="$entry.name?size=$thmb" border="0" width="$dim.width" height="$dim.height"/></a><br/>
<span class="caption">$!entry.caption</span> <span class="caption">$!entry.caption</span>