Mw_parse: Add more support for original files

pull/620/head
gnosygnu 8 years ago
parent e4e899f72a
commit ffc112a085

@ -20,6 +20,7 @@ public class Php_utl_ {
public static boolean Empty(byte[] v) {return v == null || v.length == 0;}
public static boolean Empty(boolean v) {return v == false;}
public static boolean Is_set(byte[] v) {return v != null;}
public static boolean isset(int v) {return v != Int_.Max_value;}
public static boolean isnumeric(byte[] src) {
if (src == null) return false;
int len = src.length;

@ -123,8 +123,8 @@ public class Xomw_linker {
postfix = Gfh_tag_.Div_rhs;
frame_params.align = Align__frame__none;
}
if (file != null && handler_params.width == -1) {
if (handler_params.height != -1 && file.isVectorized()) {
if (file != null && handler_params.width == Xomw_param_itm.Null_int) {
if (handler_params.height != Xomw_param_itm.Null_int && file.isVectorized()) {
// If its a vector image, and user only specifies height
// we don't want it to be limited by its "normal" width.
// global $wgSVGMaxSize;
@ -138,7 +138,7 @@ public class Xomw_linker {
|| frame_params.manual_thumb != null
|| frame_params.framed != null
|| frame_params.frameless != null
|| handler_params.width == -1
|| handler_params.width == Xomw_param_itm.Null_int
) {
// global $wgThumbLimits, $wgThumbUpright;
@ -161,7 +161,7 @@ public class Xomw_linker {
// Use width which is smaller: real image width or user preference width
// Unless image is scalable vector.
if (handler_params.height == -1 && handler_params.width <= 0 ||
if (handler_params.height == Xomw_param_itm.Null_int && handler_params.width <= 0 ||
pref_width < handler_params.width || file.isVectorized()) {
handler_params.width = pref_width;
}
@ -190,17 +190,15 @@ public class Xomw_linker {
// For "frameless" option: do not present an image bigger than the
// source (for bitmap-style images). This is the same behavior as the
// "thumb" option does it already.
if (src_width != -1 && !file.mustRender() && handler_params.width > src_width) {
if (src_width != Xomw_param_itm.Null_int && !file.mustRender() && handler_params.width > src_width) {
handler_params.width = src_width;
}
}
Xomw_MediaTransformOutput thumb = null;
if (file != null && handler_params.width != -1) {
if (file != null && handler_params.width != Xomw_param_itm.Null_int) {
// Create a resized image, without the additional thumbnail features
// $thumb = $file->transform(handler_params);
// file.getPath()
thumb = new Xomw_MediaTransformOutput(file, file.getUrl(), file.getUrl(), file.getWidth(), file.getHeight());
thumb = file.transform(handler_params);
}
else {
thumb = null;
@ -291,9 +289,9 @@ public class Xomw_linker {
frame_params.caption = Bry_.Empty;
}
if (handler_params.width == -1) {
if (handler_params.width == Xomw_param_itm.Null_int) {
// Reduce width for upright images when parameter 'upright' is used
handler_params.width = frame_params.upright != -1 ? 130 : 180;
handler_params.width = frame_params.upright != Xomw_param_itm.Null_int ? 130 : 180;
}
boolean no_scale = false;
boolean manual_thumb = false;
@ -327,7 +325,7 @@ public class Xomw_linker {
// Do not present an image bigger than the source, for bitmap-style images
// This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
int src_width = file.getWidth(page);
if (src_width != -1 && !file.mustRender() && handler_params.width > src_width) {
if (src_width != Xomw_param_itm.Null_int && !file.mustRender() && handler_params.width > src_width) {
handler_params.width = src_width;
}
// thumb = $file->transform(handler_params);

@ -751,8 +751,8 @@ public class Xomw_File {
* @return boolean
*/
public boolean mustRender() {
return true;
// return this.getHandler() && this.handler.mustRender(this);
Xomw_MediaHandler handler = this.getHandler();
return handler.mustRender(this);
}
/**
@ -1030,7 +1030,7 @@ public class Xomw_File {
* @param int flags A bitfield, may contain self::RENDER_NOW to force rendering
* @return ThumbnailImage|MediaTransformOutput|boolean False on failure
*/
// XO.MW.DFLT:flags=0;
public Xomw_MediaTransformOutput transform(Xomw_params_handler handlerParams) {return transform(handlerParams, 0);}
public Xomw_MediaTransformOutput transform(Xomw_params_handler handlerParams, int flags) {
// global wgThumbnailEpoch;
@ -1060,8 +1060,8 @@ public class Xomw_File {
// handler.normaliseParams(this, normalisedParams);
byte[] thumbName = this.thumbName(normalisedParams);
byte[] thumbUrl = this.getThumbUrl(thumbName);
byte[] thumbPath = this.getThumbPath(thumbName); // final thumb path
// byte[] thumbUrl = this.getThumbUrl(thumbName);
// byte[] thumbPath = this.getThumbPath(thumbName); // final thumb path
if (this.repo != null) {
// // Defer rendering if a 404 handler is set up...
@ -1081,9 +1081,9 @@ public class Xomw_File {
// // XXX: Pass in the storage path even though we are not rendering anything
// // and the path is supposed to be an FS path. This is due to getScalerType()
// // getting called on the path and clobbering thumb.getUrl() if it's false.
thumb = handler.getTransform(this, thumbPath, thumbUrl, handlerParams);
// thumb = handler.getTransform(this, thumbPath, thumbUrl, handlerParams);
// thumb.setStoragePath(thumbPath);
break;
// break;
// }
}
// elseif (flags & self::RENDER_FORCE) {
@ -1097,13 +1097,14 @@ public class Xomw_File {
// break;
// }
// }
// Object tmpFile = null;
Object tmpFile = null;
// tmpFile = this.makeTransformTmpFile(thumbPath);
//
// if (!tmpFile) {
// thumb = this.transformErrorOutput(thumbPath, thumbUrl, paramsMap, flags);
// } else {
// thumb = this.generateAndSaveThumb(tmpFile, paramsMap, flags);
thumb = this.generateAndSaveThumb(tmpFile, handlerParams, flags);
break;
// }
} while (thumb != null);
@ -1117,22 +1118,23 @@ public class Xomw_File {
* @param int flags
* @return boolean|MediaTransformOutput
*/
public Object generateAndSaveThumb(Object tmpFile, Object transformParams, int flags) {
public Xomw_MediaTransformOutput generateAndSaveThumb(Object tmpFile, Xomw_params_handler transformParams, int flags) {
// global wgIgnoreImageErrors;
//
// stats = RequestContext::getMain().getStats();
//
// handler = this.getHandler();
//
// normalisedParams = transformParams;
// handler.normaliseParams(this, normalisedParams);
//
// thumbName = this.thumbName(normalisedParams);
// thumbUrl = this.getThumbUrl(thumbName);
// thumbPath = this.getThumbPath(thumbName); // final thumb path
//
Xomw_MediaHandler handler = this.getHandler();
Xomw_params_handler normalisedParams = transformParams;
handler.normaliseParams(this, normalisedParams);
byte[] thumbName = this.thumbName(normalisedParams);
byte[] thumbUrl = this.getThumbUrl(thumbName);
// byte[] thumbPath = this.getThumbPath(thumbName); // final thumb path
// tmpThumbPath = tmpFile.getPath();
//
byte[] tmpThumbPath = Bry_.Empty;
// if (handler.supportsBucketing()) {
// this.generateBucketsIfNeeded(normalisedParams, flags);
// }
@ -1140,8 +1142,7 @@ public class Xomw_File {
// starttime = microtime(true);
//
// Actually render the thumbnail...
Object thumb = null;
// thumb = handler.doTransform(this, tmpThumbPath, thumbUrl, transformParams);
Xomw_MediaTransformOutput thumb = handler.doTransform(this, tmpThumbPath, thumbUrl, transformParams);
// tmpFile.bind(thumb); // keep alive with thumb
//
// statTiming = microtime(true) - starttime;

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
import gplx.xowa.mws.filerepo.file.*; import gplx.xowa.mws.parsers.lnkis.*;
import gplx.langs.phps.utls.*;
// MEMORY:only one instance per wiki
public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private final Xomw_param_map paramMap = new Xomw_param_map();
public Xomw_ImageHandler(byte[] key) {super(key);
@ -27,7 +28,7 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
* @return boolean
*/
@Override public boolean canRender(Xomw_File file) {
return (file.getWidth(1) != -1 && file.getHeight(1) != -1);
return (file.getWidth(1) != Xomw_param_itm.Null_int && file.getHeight(1) != Xomw_param_itm.Null_int);
}
@Override public Xomw_param_map getParamMap() {
@ -50,10 +51,10 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
@Override public byte[] makeParamString(Xomw_params_handler handlerParams) {
int width = 0;
if (handlerParams.physicalWidth != -1) {
if (handlerParams.physicalWidth != Xomw_param_itm.Null_int) {
width = handlerParams.physicalWidth;
}
else if (handlerParams.width != -1) {
else if (handlerParams.width != Xomw_param_itm.Null_int) {
width = handlerParams.width;
}
else {
@ -74,81 +75,82 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// }
// }
//
// function getScriptParams(params) {
// return [ 'width' => params['width'] ];
// function getScriptParams(paramsVar) {
// return [ 'width' => paramsVar['width'] ];
// }
//
// /**
// * @param File image
// * @param array params
// * @return boolean
// */
// function normaliseParams(image, &params) {
/**
* @param File image
* @param array paramsVar
* @return boolean
*/
@Override public boolean normaliseParams(Xomw_File image, Xomw_params_handler handlerParams) {
// mimeType = image.getMimeType();
//
// if (!isset(params['width'])) {
// return false;
// }
//
// if (!isset(params['page'])) {
// params['page'] = 1;
// } else {
// params['page'] = intval(params['page']);
// if (params['page'] > image.pageCount()) {
// params['page'] = image.pageCount();
// }
//
// if (params['page'] < 1) {
// params['page'] = 1;
if (!Php_utl_.isset(handlerParams.width)) {
return false;
}
if (!Php_utl_.isset(handlerParams.page)) {
handlerParams.page = 1;
}
else {
// handlerParams.page = intval(handlerParams.page);
// if (handlerParams.page > image.pageCount()) {
// handlerParams.page = image.pageCount();
// }
// }
//
// srcWidth = image.getWidth(params['page']);
// srcHeight = image.getHeight(params['page']);
//
// if (isset(params['height']) && params['height'] != -1) {
// # Height & width were both set
// if (params['width'] * srcHeight > params['height'] * srcWidth) {
// # Height is the relative smaller dimension, so scale width accordingly
// params['width'] = self::fitBoxWidth(srcWidth, srcHeight, params['height']);
//
// if (params['width'] == 0) {
// # Very small image, so we need to rely on client side scaling :(
// params['width'] = 1;
// }
//
// params['physicalWidth'] = params['width'];
// } else {
// # Height was crap, unset it so that it will be calculated later
// unset(params['height']);
// if (handlerParams.page < 1) {
// handlerParams.page = 1;
// }
// }
//
// if (!isset(params['physicalWidth'])) {
// # Passed all validations, so set the physicalWidth
// params['physicalWidth'] = params['width'];
// }
//
// # Because thumbs are only referred to by width, the height always needs
// # to be scaled by the width to keep the thumbnail sizes consistent,
// # even if it was set inside the if block above
// params['physicalHeight'] = File::scaleHeight(srcWidth, srcHeight,
// params['physicalWidth']);
//
// # Set the height if it was not validated in the if block higher up
// if (!isset(params['height']) || params['height'] == -1) {
// params['height'] = params['physicalHeight'];
// }
//
// if (!this.validateThumbParams(params['physicalWidth'],
// params['physicalHeight'], srcWidth, srcHeight, mimeType)
}
int srcWidth = image.getWidth(handlerParams.page);
int srcHeight = image.getHeight(handlerParams.page);
if (Php_utl_.isset(handlerParams.height) && handlerParams.height != -1) {
// Height & width were both set
if (handlerParams.width * srcHeight > handlerParams.height * srcWidth) {
// Height is the relative smaller dimension, so scale width accordingly
// handlerParams.width = self::fitBoxWidth(srcWidth, srcHeight, handlerParams.height);
if (handlerParams.width == 0) {
// Very small image, so we need to rely on client side scaling :(
handlerParams.width = 1;
}
handlerParams.physicalWidth = handlerParams.width;
} else {
// Height was crap, unset it so that it will be calculated later
handlerParams.height = Xomw_param_itm.Null_int;
}
}
if (!Php_utl_.isset(handlerParams.physicalWidth)) {
// Passed all validations, so set the physicalWidth
handlerParams.physicalWidth = handlerParams.width;
}
// Because thumbs are only referred to by width, the height always needs
// to be scaled by the width to keep the thumbnail sizes consistent,
// even if it was set inside the if block above
// handlerParams.physicalHeight = File::scaleHeight(srcWidth, srcHeight,
// handlerParams.physicalWidth);
// Set the height if it was not validated in the if block higher up
if (!Php_utl_.isset(handlerParams.height) || handlerParams.height == -1) {
handlerParams.height = handlerParams.physicalHeight;
}
// if (!this.validateThumbParams(handlerParams.physicalWidth,
// handlerParams.physicalHeight, srcWidth, srcHeight, mimeType)
// ) {
// return false;
// }
//
// return true;
// }
//
return true;
}
// /**
// * Validate thumbnail parameters and fill in the correct height
// *
@ -186,17 +188,17 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// /**
// * @param File image
// * @param String script
// * @param array params
// * @param array paramsVar
// * @return boolean|MediaTransformOutput
// */
// function getScriptedTransform(image, script, params) {
// if (!this.normaliseParams(image, params)) {
// function getScriptedTransform(image, script, paramsVar) {
// if (!this.normaliseParams(image, paramsVar)) {
// return false;
// }
// url = wfAppendQuery(script, this.getScriptParams(params));
// url = wfAppendQuery(script, this.getScriptParams(paramsVar));
//
// if (image.mustRender() || params['width'] < image.getWidth()) {
// return new ThumbnailImage(image, url, false, params);
// if (image.mustRender() || paramsVar['width'] < image.getWidth()) {
// return new ThumbnailImage(image, url, false, paramsVar);
// }
// }
//
@ -244,11 +246,11 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// size = htmlspecialchars(wgLang.formatSize(file.getSize()));
// if (pages === false || pages <= 1) {
// msg = wfMessage('file-info-size').numParams(file.getWidth(),
// file.getHeight()).params(size,
// file.getHeight()).paramsVar(size,
// '<span class="mime-type">' . file.getMimeType() . '</span>').parse();
// } else {
// msg = wfMessage('file-info-size-pages').numParams(file.getWidth(),
// file.getHeight()).params(size,
// file.getHeight()).paramsVar(size,
// '<span class="mime-type">' . file.getMimeType() . '</span>').numParams(pages).parse();
// }
//
@ -270,19 +272,19 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// }
// }
//
// public function sanitizeParamsForBucketing(params) {
// params = parent::sanitizeParamsForBucketing(params);
// public function sanitizeParamsForBucketing(paramsVar) {
// paramsVar = parent::sanitizeParamsForBucketing(paramsVar);
//
// // We unset the height parameters in order to let normaliseParams recalculate them
// // Otherwise there might be a height discrepancy
// if (isset(params['height'])) {
// unset(params['height']);
// if (isset(paramsVar['height'])) {
// unset(paramsVar['height']);
// }
//
// if (isset(params['physicalHeight'])) {
// unset(params['physicalHeight']);
// if (isset(paramsVar['physicalHeight'])) {
// unset(paramsVar['physicalHeight']);
// }
//
// return params;
// return paramsVar;
// }
}

@ -75,16 +75,16 @@ public abstract class Xomw_MediaHandler {
// * @return array|boolean Array of parameters or false on failure.
// */
// abstract public function parseParamString($str);
//
// /**
// * Changes the parameter array as necessary, ready for transformation.
// * Should be idempotent.
// * Returns false if the parameters are unacceptable and the transform should fail
// * @param File $image
// * @param array $paramsVar
// */
// abstract function normaliseParams($image, &$paramsVar);
//
/**
* Changes the parameter array as necessary, ready for transformation.
* Should be idempotent.
* Returns false if the parameters are unacceptable and the transform should fail
* @param File $image
* @param array $paramsVar
*/
public abstract boolean normaliseParams(Xomw_File image, Xomw_params_handler handlerParams);
// /**
// * Get an image size array like that returned by getimagesize(), or false if it
// * can't be determined.
@ -274,7 +274,7 @@ public abstract class Xomw_MediaHandler {
* @param int $flags A bitfield, may contain self::TRANSFORM_LATER
* @return MediaTransformOutput
*/
// XO.MW:flags=0
public Xomw_MediaTransformOutput doTransform(Xomw_File image, byte[] dstPath, byte[] dstUrl, Xomw_params_handler handlerParams) {return doTransform(image, dstPath, dstUrl, handlerParams, 0);}
public abstract Xomw_MediaTransformOutput doTransform(Xomw_File image, byte[] dstPath, byte[] dstUrl, Xomw_params_handler handlerParams, int flags);
// /**
@ -320,18 +320,18 @@ public abstract class Xomw_MediaHandler {
@gplx.Virtual public boolean canRender(Xomw_File file) {
return true;
}
//
// /**
// * True if handled types cannot be displayed directly in a browser
// * but can be rendered
// *
// * @param File $file
// * @return boolean
// */
// public function mustRender($file) {
// return false;
// }
//
/**
* True if handled types cannot be displayed directly in a browser
* but can be rendered
*
* @param File $file
* @return boolean
*/
public boolean mustRender(Xomw_File file) {
return false;
}
// /**
// * True if the type has multi-page capabilities
// *

@ -21,37 +21,37 @@ import gplx.xowa.mws.parsers.lnkis.*;
public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { public Xomw_TransformationalImageHandler(byte[] key) {super(key);
}
// /**
// * @param File image
// * @param array paramsVar Transform parameters. Entries with the keys 'width'
// * and 'height' are the respective screen width and height, while the keys
// * 'physicalWidth' and 'physicalHeight' indicate the thumbnail dimensions.
// * @return boolean
// */
// function normaliseParams(image, &paramsVar) {
// if (!parent::normaliseParams(image, paramsVar)) {
// return false;
// }
//
// // Obtain the source, pre-rotation dimensions
// srcWidth = image.getWidth(paramsVar['page']);
// srcHeight = image.getHeight(paramsVar['page']);
//
// // Don't make an image bigger than the source
// if (paramsVar['physicalWidth'] >= srcWidth) {
// paramsVar['physicalWidth'] = srcWidth;
// paramsVar['physicalHeight'] = srcHeight;
//
// // Skip scaling limit checks if no scaling is required
// // due to requested size being bigger than source.
// if (!image.mustRender()) {
// return true;
// }
// }
//
// return true;
// }
//
/**
* @param File image
* @param array paramsVar Transform parameters. Entries with the keys 'width'
* and 'height' are the respective screen width and height, while the keys
* 'physicalWidth' and 'physicalHeight' indicate the thumbnail dimensions.
* @return boolean
*/
@Override public boolean normaliseParams(Xomw_File image, Xomw_params_handler handlerParams) {
if (!super.normaliseParams(image, handlerParams)) {
return false;
}
// Obtain the source, pre-rotation dimensions
int srcWidth = image.getWidth(handlerParams.page);
int srcHeight = image.getHeight(handlerParams.page);
// Don't make an image bigger than the source
if (handlerParams.physicalWidth >= srcWidth) {
handlerParams.physicalWidth = srcWidth;
handlerParams.physicalHeight = srcHeight;
// Skip scaling limit checks if no scaling is required
// due to requested size being bigger than source.
if (!image.mustRender()) {
return true;
}
}
return true;
}
// /**
// * Extracts the width/height if the image will be scaled before rotating
// *
@ -96,37 +96,36 @@ public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { publi
// }
//
// // Create a parameter array to pass to the scaler
// scalerParams = [
// // The size to which the image will be resized
// 'physicalWidth' => paramsVar['physicalWidth'],
// 'physicalHeight' => paramsVar['physicalHeight'],
// 'physicalDimensions' => "{paramsVar['physicalWidth']}x{paramsVar['physicalHeight']}",
// // The size of the image on the page
// 'clientWidth' => paramsVar['width'],
// 'clientHeight' => paramsVar['height'],
// // Comment as will be added to the Exif of the thumbnail
// 'comment' => isset(paramsVar['descriptionUrl'])
// ? "File source: {paramsVar['descriptionUrl']}"
// : '',
// // Properties of the original image
// 'srcWidth' => image.getWidth(),
// 'srcHeight' => image.getHeight(),
// 'mimeType' => image.getMimeType(),
// 'dstPath' => dstPath,
// 'dstUrl' => dstUrl,
// 'interlace' => isset(paramsVar['interlace']) ? paramsVar['interlace'] : false,
// ];
//
Xomw_params_scalar scalerParams = new Xomw_params_scalar();
// // The size to which the image will be resized
scalerParams.physicalWidth = handlerParams.physicalWidth;
scalerParams.physicalHeight = handlerParams.physicalHeight;
// 'physicalDimensions' => "{paramsVar['physicalWidth']}x{paramsVar['physicalHeight']}",
// The size of the image on the page
scalerParams.clientWidth = handlerParams.width;
scalerParams.clientHeight = handlerParams.height;
// Comment as will be added to the Exif of the thumbnail
// 'comment' => isset(paramsVar['descriptionUrl'])
// ? "File source: {paramsVar['descriptionUrl']}"
// : '',
// Properties of the original image
scalerParams.srcWidth = image.getWidth();
scalerParams.srcHeight = image.getHeight();
scalerParams.mimeType = image.getMimeType();
scalerParams.dstPath = dstPath;
scalerParams.dstUrl = dstUrl;
// 'interlace' => isset(paramsVar['interlace']) ? paramsVar['interlace'] : false,
// if (isset(paramsVar['quality']) && paramsVar['quality'] === 'low') {
// scalerParams['quality'] = 30;
// }
//
// // For subclasses that might be paged.
// For subclasses that might be paged.
// if (image.isMultipage() && isset(paramsVar['page'])) {
// scalerParams['page'] = intval(paramsVar['page']);
// }
//
// // Determine scaler type
// Determine scaler type
// scaler = this.getScalerType(dstPath);
//
// if (is_array(scaler)) {
@ -137,19 +136,19 @@ public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { publi
//
// wfDebug(__METHOD__ . ": creating {scalerParams['physicalDimensions']} " .
// "thumbnail at dstPath using scaler scalerName\n");
//
// if (!image.mustRender() &&
// scalerParams['physicalWidth'] == scalerParams['srcWidth']
// && scalerParams['physicalHeight'] == scalerParams['srcHeight']
if (!image.mustRender() &&
scalerParams.physicalWidth == scalerParams.srcWidth
&& scalerParams.physicalHeight == scalerParams.srcHeight
// && !isset(scalerParams['quality'])
// ) {
//
// // normaliseParams (or the user) wants us to return the unscaled image
) {
// normaliseParams (or the user) wants us to return the unscaled image
// wfDebug(__METHOD__ . ": returning unscaled image\n");
//
// return this.getClientScalingThumbnailImage(image, scalerParams);
// }
//
return this.getClientScalingThumbnailImage(image, scalerParams);
}
// if (scaler == 'client') {
// // Client-side image scaling, use the source URL
// // Using the destination URL in a TRANSFORM_LATER request would be incorrect
@ -308,26 +307,25 @@ public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { publi
// * @return String|Callable One of client, im, custom, gd, imext, or a Callable array.
// */
// abstract protected function getScalerType(dstPath, checkDstPath = true);
//
// /**
// * Get a ThumbnailImage that respresents an image that will be scaled
// * client side
// *
// * @param File image File associated with this thumbnail
// * @param array scalerParams Array with scaler paramsVar
// * @return ThumbnailImage
// *
// * @todo FIXME: No rotation support
// */
// protected function getClientScalingThumbnailImage(image, scalerParams) {
// paramsVar = [
// 'width' => scalerParams['clientWidth'],
// 'height' => scalerParams['clientHeight']
// ];
//
// return new ThumbnailImage(image, image.getUrl(), null, paramsVar);
// }
//
/**
* Get a ThumbnailImage that respresents an image that will be scaled
* client side
*
* @param File image File associated with this thumbnail
* @param array scalerParams Array with scaler paramsVar
* @return ThumbnailImage
*
* @todo FIXME: No rotation support
*/
private Xomw_ThumbnailImage getClientScalingThumbnailImage(Xomw_File image, Xomw_params_scalar scalerParams) {
Xomw_params_handler handler_params = new Xomw_params_handler();
handler_params.width = scalerParams.clientWidth;
handler_params.height = scalerParams.clientHeight;
return new Xomw_ThumbnailImage(image, image.getUrl(), image.getPath(), handler_params);
}
// /**
// * Transform an image using ImageMagick
// *

@ -743,7 +743,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// Parsed a width param of imagelink like 300px or 200x300px
// XO.MW.NOTE: for MW, "" -> null, null while "AxB" -> 0x0
public void parseWidthParam(int[] img_size, byte[] src) {
img_size[0] = img_size[1] = -1;
img_size[0] = img_size[1] = Xomw_param_itm.Null_int;
if (src == Bry_.Empty) {
return;
}

@ -30,7 +30,7 @@ public class Xomw_lnki_wkr__file__tst {
fxt.Test__to_html("[[File:A.png|thumb]]", "<div class='thumb tright'><div class='thumbinner' style='width:222px;'><a><img alt='A.png' src='/thumb/7/70/A.png/220px-A.png' class='thumbimage' /></a> <div class='thumbcaption'><div class='magnify'><a href='' class='internal'></a></div></div></div></div>");
}
@Test public void Size() {
fxt.Test__to_html("[[File:A.png|123x456px]]", "<img alt='A.png' src='/orig/7/70/A.png' />");
fxt.Test__to_html("[[File:A.png|123x456px]]", "<img alt='A.png' src='/thumb/7/70/A.png/123px-A.png' />");
}
@Test public void Test__parseWidthParam() {
int[] img_size = new int[2];

@ -54,4 +54,6 @@ public class Xomw_param_itm {
public static final byte[]
Name_bry__width = Bry_.new_a7("width")
;
public static final int Null_int = Int_.Max_value;
}

@ -17,20 +17,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
public class Xomw_params_handler {
public int width = -1;
public int height = -1;
public int page = -1;
public int physicalWidth = -1;
public int width;
public int height;
public int page;
public int physicalWidth;
public int physicalHeight;
public Xomw_params_handler Clear() {
width = height = page = -1;
physicalWidth = -1;
width = height = page
= physicalWidth = physicalHeight = Xomw_param_itm.Null_int;
return this;
}
public void Copy_to(Xomw_params_handler src) {
this.width = src.width;
this.height = src.height;
this.page = src.page;
this.physicalWidth = -1;
this.physicalWidth = src.physicalWidth;
this.physicalHeight = src.physicalHeight;
}
public void Set(int uid, byte[] val_bry, int val_int) {
switch (uid) {

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
public class Xomw_params_scalar {
public int physicalWidth;
public int physicalHeight;
public byte[] physicalDimensions;
public int clientWidth;
public int clientHeight;
public byte[] comment;
public int srcWidth;
public int srcHeight;
public byte[] mimeType;
public byte[] dstPath;
public byte[] dstUrl;
public byte[] interlace;
public Xomw_params_scalar() {
physicalWidth = physicalHeight = clientWidth = clientHeight = srcWidth = srcHeight = Xomw_param_itm.Null_int;
}
}
Loading…
Cancel
Save