// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
//
//
// Encapsulates methods to rotate an image without expanding the canvas.
//
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Processors
{
using System;
using System.Text.RegularExpressions;
using ImageProcessor.Processors;
using ImageProcessor.Web.Helpers;
///
/// Encapsulates methods to rotate an image without expanding the canvas.
///
public class RotateBounded : IWebGraphicsProcessor
{
///
/// The regular expression to search strings for.
///
private static readonly Regex QueryRegex = new Regex(@"rotatebounded=[^&]+", RegexOptions.Compiled);
///
/// The regular expression to search for.
///
private static readonly Regex BoundRegex = new Regex(@"rotatebounded.keepsize=true", RegexOptions.Compiled);
///
/// Initializes a new instance of the class.
///
public RotateBounded()
{
this.Processor = new ImageProcessor.Processors.RotateBounded();
}
#region IGraphicsProcessor Members
///
/// Gets the regular expression to search strings for.
///
public Regex RegexPattern
{
get
{
return QueryRegex;
}
}
///
/// Gets the order in which this processor is to be used in a chain.
///
public int SortOrder
{
get;
private set;
}
///
/// Gets the associated graphics processor.
///
public IGraphicsProcessor Processor { get; private set; }
///
/// The position in the original string where the first character of the captured substring was found.
///
///
/// The query string to search.
///
///
/// The zero-based starting position in the original string where the captured substring was found.
///
public int MatchRegexIndex(string queryString)
{
int index = 0;
// Set the sort order to max to allow filtering.
this.SortOrder = int.MaxValue;
foreach (Match match in this.RegexPattern.Matches(queryString))
{
if (match.Success)
{
if (index == 0)
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
float angle = CommonParameterParserUtility.ParseAngle(match.Value);
bool keepSize = BoundRegex.Match(queryString).Success;
Tuple rotateParams = new Tuple(angle, keepSize);
this.Processor.DynamicParameter = rotateParams;
}
index += 1;
}
}
return this.SortOrder;
}
#endregion
}
}