-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #817 from ad619659/design_refactorings
Design refactoring for CounterFunction/FSLinearGradient
- Loading branch information
Showing
6 changed files
with
146 additions
and
142 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
openhtmltopdf-core/src/main/java/com/openhtmltopdf/context/ContentFunctionAbstract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.openhtmltopdf.context; | ||
|
||
import com.openhtmltopdf.css.extend.ContentFunction; | ||
|
||
public abstract class ContentFunctionAbstract implements ContentFunction { | ||
public boolean isStatic() { | ||
return false; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...tmltopdf-core/src/main/java/com/openhtmltopdf/css/style/derived/FSLinearGradientUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.openhtmltopdf.css.style.derived; | ||
|
||
import com.openhtmltopdf.css.constants.CSSName; | ||
import com.openhtmltopdf.css.constants.Idents; | ||
import com.openhtmltopdf.css.parser.CSSPrimitiveValue; | ||
import com.openhtmltopdf.css.parser.PropertyValue; | ||
import com.openhtmltopdf.css.parser.property.AbstractPropertyBuilder; | ||
import com.openhtmltopdf.css.style.CalculatedStyle; | ||
import com.openhtmltopdf.css.style.CssContext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class FSLinearGradientUtil { | ||
static float deg2rad(final float deg) { | ||
return (float) Math.toRadians(deg); | ||
} | ||
|
||
static boolean isLengthOrPercentage(PropertyValue value) { | ||
return AbstractPropertyBuilder.isLengthHelper(value) || | ||
value.getPrimitiveType() == CSSPrimitiveValue.CSS_PERCENTAGE; | ||
} | ||
|
||
static int getStopsStartIndex(List<PropertyValue> params) { | ||
if (Objects.equals(params.get(0).getStringValue(), "to")) { | ||
int i = 1; | ||
while (i < params.size() && | ||
params.get(i).getStringValue() != null && | ||
Idents.looksLikeABGPosition(params.get(i).getStringValue())) { | ||
i++; | ||
} | ||
|
||
return i; | ||
} else { | ||
return 1; | ||
} | ||
} | ||
|
||
static float get100PercentDefaultStopLength(CalculatedStyle style, CssContext ctx, float boxWidth) { | ||
return LengthValue.calcFloatProportionalValue(style, CSSName.BACKGROUND_IMAGE, "100%", | ||
100f, CSSPrimitiveValue.CSS_PERCENTAGE, boxWidth, ctx); | ||
} | ||
|
||
/** | ||
* Calculates the angle of the linear gradient in degrees. | ||
*/ | ||
static float calculateAngle(List<PropertyValue> params, int stopsStartIndex) { | ||
if (Objects.equals(params.get(0).getStringValue(), "to")) { | ||
// The to keyword is followed by one or two position | ||
// idents (in any order). | ||
// linear-gradient( to left top, blue, red); | ||
// linear-gradient( to top right, blue, red); | ||
List<String> positions = new ArrayList<>(2); | ||
|
||
for (int i = 1; i < stopsStartIndex; i++) { | ||
positions.add(params.get(i).getStringValue()); | ||
} | ||
|
||
if (positions.contains("top") && positions.contains("left")) | ||
return 315f; | ||
else if (positions.contains("top") && positions.contains("right")) | ||
return 45f; | ||
else if (positions.contains("bottom") && positions.contains("left")) | ||
return 225f; | ||
else if (positions.contains("bottom") && positions.contains("right")) | ||
return 135f; | ||
else if (positions.contains("bottom")) | ||
return 180f; | ||
else if (positions.contains("left")) | ||
return 270f; | ||
else if (positions.contains("right")) | ||
return 90f; | ||
else | ||
return 0f; | ||
} | ||
else if (params.get(0).getPrimitiveType() == CSSPrimitiveValue.CSS_DEG) | ||
{ | ||
// linear-gradient(45deg, ...) | ||
return params.get(0).getFloatValue(); | ||
} | ||
else if (params.get(0).getPrimitiveType() == CSSPrimitiveValue.CSS_RAD) | ||
{ | ||
// linear-gradient(2rad) | ||
return params.get(0).getFloatValue() * (float) (180 / Math.PI); | ||
} | ||
else | ||
{ | ||
return 0f; | ||
} | ||
} | ||
} |
Oops, something went wrong.