Simplify naming

This commit is contained in:
Mikael Sand
2017-07-22 05:31:32 +03:00
parent 93d507b029
commit a103cef1a6
2 changed files with 152 additions and 143 deletions
@@ -24,25 +24,25 @@ class GlyphContext {
private static final float DEFAULT_LETTER_SPACING = 0f;
// Unique input attribute lists (only added if node sets a value)
private final ArrayList<String[]> mXPositionsContext = new ArrayList<>();
private final ArrayList<String[]> mYPositionsContext = new ArrayList<>();
private final ArrayList<float[]> mRotationsContext = new ArrayList<>();
private final ArrayList<float[]> mDeltaXsContext = new ArrayList<>();
private final ArrayList<float[]> mDeltaYsContext = new ArrayList<>();
private final ArrayList<String[]> mXsContext = new ArrayList<>();
private final ArrayList<String[]> mYsContext = new ArrayList<>();
private final ArrayList<float[]> mRsContext = new ArrayList<>();
private final ArrayList<float[]> mdXsContext = new ArrayList<>();
private final ArrayList<float[]> mdYsContext = new ArrayList<>();
// Unique index into attribute list (one per unique list)
private final ArrayList<Integer> mXPositionIndices = new ArrayList<>();
private final ArrayList<Integer> mYPositionIndices = new ArrayList<>();
private final ArrayList<Integer> mRotationIndices = new ArrayList<>();
private final ArrayList<Integer> mDeltaXIndices = new ArrayList<>();
private final ArrayList<Integer> mDeltaYIndices = new ArrayList<>();
private final ArrayList<Integer> mXIndices = new ArrayList<>();
private final ArrayList<Integer> mYIndices = new ArrayList<>();
private final ArrayList<Integer> mRIndices = new ArrayList<>();
private final ArrayList<Integer> mdXIndices = new ArrayList<>();
private final ArrayList<Integer> mdYIndices = new ArrayList<>();
// Index of unique context used (one per node push/pop)
private final ArrayList<Integer> mXPositionsIndices = new ArrayList<>();
private final ArrayList<Integer> mYPositionsIndices = new ArrayList<>();
private final ArrayList<Integer> mRotationsIndices = new ArrayList<>();
private final ArrayList<Integer> mDeltaXsIndices = new ArrayList<>();
private final ArrayList<Integer> mDeltaYsIndices = new ArrayList<>();
private final ArrayList<Integer> mXsIndices = new ArrayList<>();
private final ArrayList<Integer> mYsIndices = new ArrayList<>();
private final ArrayList<Integer> mRsIndices = new ArrayList<>();
private final ArrayList<Integer> mdXsIndices = new ArrayList<>();
private final ArrayList<Integer> mdYsIndices = new ArrayList<>();
// Current stack (one per node push/pop)
private final ArrayList<ReadableMap> mFontContext = new ArrayList<>();
@@ -61,23 +61,23 @@ class GlyphContext {
// Current attribute list
private String[] mXs = new String[]{};
private String[] mYs = new String[]{};
private float[] mRotations = new float[]{0};
private float[] mDeltaXs = new float[]{};
private float[] mDeltaYs = new float[]{};
private float[] mRs = new float[]{0};
private float[] mdXs = new float[]{};
private float[] mdYs = new float[]{};
// Current attribute list index
private int mXPositionsIndex;
private int mYPositionsIndex;
private int mRotationsIndex;
private int mDeltaXsIndex;
private int mDeltaYsIndex;
private int mXsIndex;
private int mYsIndex;
private int mRsIndex;
private int mdXsIndex;
private int mdYsIndex;
// Current value index in current attribute list
private int mXPositionIndex = -1;
private int mYPositionIndex = -1;
private int mRotationIndex = -1;
private int mDeltaXIndex = -1;
private int mDeltaYIndex = -1;
private int mXIndex = -1;
private int mYIndex = -1;
private int mRIndex = -1;
private int mdXIndex = -1;
private int mdYIndex = -1;
// Stack length and last index
private int mContextLength;
@@ -93,17 +93,17 @@ class GlyphContext {
mWidth = width;
mHeight = height;
mXPositionsContext.add(mXs);
mYPositionsContext.add(mYs);
mDeltaXsContext.add(mDeltaXs);
mDeltaYsContext.add(mDeltaYs);
mRotationsContext.add(mRotations);
mXsContext.add(mXs);
mYsContext.add(mYs);
mdXsContext.add(mdXs);
mdYsContext.add(mdYs);
mRsContext.add(mRs);
mXPositionIndices.add(mXPositionIndex);
mYPositionIndices.add(mYPositionIndex);
mRotationIndices.add(mRotationIndex);
mDeltaXIndices.add(mDeltaXIndex);
mDeltaYIndices.add(mDeltaYIndex);
mXIndices.add(mXIndex);
mYIndices.add(mYIndex);
mRIndices.add(mRIndex);
mdXIndices.add(mdXIndex);
mdYIndices.add(mdYIndex);
pushIndices();
}
@@ -118,49 +118,58 @@ class GlyphContext {
fontSize = getFontSize();
}
void pushContext(TextShadowNode node, @Nullable ReadableMap font, @Nullable ReadableArray rotate, @Nullable ReadableArray deltaX, @Nullable ReadableArray deltaY, @Nullable String positionX, @Nullable String positionY, boolean resetPosition) {
if (resetPosition) {
reset();
void pushContext(
TextShadowNode node,
@Nullable ReadableMap font,
boolean reset,
@Nullable String x,
@Nullable String y,
@Nullable ReadableArray rotate,
@Nullable ReadableArray deltaX,
@Nullable ReadableArray deltaY
) {
if (reset) {
this.reset();
}
if (positionX != null) {
mXPositionsIndex++;
mXPositionIndex = -1;
mXPositionIndices.add(mXPositionIndex);
mXs = positionX.trim().split("\\s+");
mXPositionsContext.add(mXs);
if (x != null) {
mXsIndex++;
mXIndex = -1;
mXIndices.add(mXIndex);
mXs = x.trim().split("\\s+");
mXsContext.add(mXs);
}
if (positionY != null) {
mYPositionsIndex++;
mYPositionIndex = -1;
mYPositionIndices.add(mYPositionIndex);
mYs = positionY.trim().split("\\s+");
mYPositionsContext.add(mYs);
if (y != null) {
mYsIndex++;
mYIndex = -1;
mYIndices.add(mYIndex);
mYs = y.trim().split("\\s+");
mYsContext.add(mYs);
}
if (rotate != null && rotate.size() != 0) {
mRotationsIndex++;
mRotationIndex = -1;
mRotationIndices.add(mRotationIndex);
mRotations = getFloatArrayFromReadableArray(rotate);
mRotationsContext.add(mRotations);
mRsIndex++;
mRIndex = -1;
mRIndices.add(mRIndex);
mRs = getFloatArrayFromReadableArray(rotate);
mRsContext.add(mRs);
}
if (deltaX != null && deltaX.size() != 0) {
mDeltaXsIndex++;
mDeltaXIndex = -1;
mDeltaXIndices.add(mDeltaXIndex);
mDeltaXs = getFloatArrayFromReadableArray(deltaX);
mDeltaXsContext.add(mDeltaXs);
mdXsIndex++;
mdXIndex = -1;
mdXIndices.add(mdXIndex);
mdXs = getFloatArrayFromReadableArray(deltaX);
mdXsContext.add(mdXs);
}
if (deltaY != null && deltaY.size() != 0) {
mDeltaYsIndex++;
mDeltaYIndex = -1;
mDeltaYIndices.add(mDeltaYIndex);
mDeltaYs = getFloatArrayFromReadableArray(deltaY);
mDeltaYsContext.add(mDeltaYs);
mdYsIndex++;
mdYIndex = -1;
mdYIndices.add(mdYIndex);
mdYs = getFloatArrayFromReadableArray(deltaY);
mdYsContext.add(mdYs);
}
mFontContext.add(font);
@@ -173,16 +182,16 @@ class GlyphContext {
}
private void pushIndices() {
mXPositionsIndices.add(mXPositionsIndex);
mYPositionsIndices.add(mYPositionsIndex);
mRotationsIndices.add(mRotationsIndex);
mDeltaXsIndices.add(mDeltaXsIndex);
mDeltaYsIndices.add(mDeltaYsIndex);
mXsIndices.add(mXsIndex);
mYsIndices.add(mYsIndex);
mRsIndices.add(mRsIndex);
mdXsIndices.add(mdXsIndex);
mdYsIndices.add(mdYsIndex);
}
private void reset() {
mXPositionsIndex = mYPositionsIndex = mRotationsIndex = mDeltaXsIndex = mDeltaYsIndex = 0;
mXPositionIndex = mYPositionIndex = mRotationIndex = mDeltaXIndex = mDeltaYIndex = -1;
mXsIndex = mYsIndex = mRsIndex = mdXsIndex = mdYsIndex = 0;
mXIndex = mYIndex = mRIndex = mdXIndex = mdYIndex = -1;
mx = my = mr = mdx = mdy = 0;
}
@@ -190,64 +199,64 @@ class GlyphContext {
mContextLength--;
top--;
mFontContext.remove(mContextLength);
mNodes.remove(mContextLength);
mFontContext.remove(mContextLength);
mXPositionsIndices.remove(mContextLength);
mYPositionsIndices.remove(mContextLength);
mRotationsIndices.remove(mContextLength);
mDeltaXsIndices.remove(mContextLength);
mDeltaYsIndices.remove(mContextLength);
mXsIndices.remove(mContextLength);
mYsIndices.remove(mContextLength);
mRsIndices.remove(mContextLength);
mdXsIndices.remove(mContextLength);
mdYsIndices.remove(mContextLength);
int x = mXPositionsIndex;
int y = mYPositionsIndex;
int r = mRotationsIndex;
int dx = mDeltaXsIndex;
int dy = mDeltaYsIndex;
int x = mXsIndex;
int y = mYsIndex;
int r = mRsIndex;
int dx = mdXsIndex;
int dy = mdYsIndex;
mXPositionsIndex = mXPositionsIndices.get(mContextLength);
mYPositionsIndex = mYPositionsIndices.get(mContextLength);
mRotationsIndex = mRotationsIndices.get(mContextLength);
mDeltaXsIndex = mDeltaXsIndices.get(mContextLength);
mDeltaYsIndex = mDeltaYsIndices.get(mContextLength);
mXsIndex = mXsIndices.get(mContextLength);
mYsIndex = mYsIndices.get(mContextLength);
mRsIndex = mRsIndices.get(mContextLength);
mdXsIndex = mdXsIndices.get(mContextLength);
mdYsIndex = mdYsIndices.get(mContextLength);
if (x != mXPositionsIndex) {
mXPositionsContext.remove(x);
mXs = mXPositionsContext.get(mXPositionsIndex);
mXPositionIndex = mXPositionIndices.get(mXPositionsIndex);
if (x != mXsIndex) {
mXsContext.remove(x);
mXs = mXsContext.get(mXsIndex);
mXIndex = mXIndices.get(mXsIndex);
}
if (y != mYPositionsIndex) {
mYPositionsContext.remove(y);
mYs = mYPositionsContext.get(mYPositionsIndex);
mYPositionIndex = mYPositionIndices.get(mYPositionsIndex);
if (y != mYsIndex) {
mYsContext.remove(y);
mYs = mYsContext.get(mYsIndex);
mYIndex = mYIndices.get(mYsIndex);
}
if (r != mRotationsIndex) {
mRotationsContext.remove(r);
mRotations = mRotationsContext.get(mRotationsIndex);
mRotationIndex = mRotationIndices.get(mRotationsIndex);
if (r != mRsIndex) {
mRsContext.remove(r);
mRs = mRsContext.get(mRsIndex);
mRIndex = mRIndices.get(mRsIndex);
}
if (dx != mDeltaXsIndex) {
mDeltaXsContext.remove(dx);
mDeltaXs = mDeltaXsContext.get(mDeltaXsIndex);
mDeltaXIndex = mDeltaXIndices.get(mDeltaXsIndex);
if (dx != mdXsIndex) {
mdXsContext.remove(dx);
mdXs = mdXsContext.get(mdXsIndex);
mdXIndex = mdXIndices.get(mdXsIndex);
}
if (dy != mDeltaYsIndex) {
mDeltaYsContext.remove(dy);
mDeltaYs = mDeltaYsContext.get(mDeltaYsIndex);
mDeltaYIndex = mDeltaYIndices.get(mDeltaYsIndex);
if (dy != mdYsIndex) {
mdYsContext.remove(dy);
mdYs = mdYsContext.get(mdYsIndex);
mdYIndex = mdYIndices.get(mdYsIndex);
}
}
float nextX(float glyphWidth) {
for (int index = mXPositionsIndex; index >= 0; index--) {
int positionIndex = mXPositionIndices.get(index);
mXPositionIndices.set(index, positionIndex + 1);
for (int index = mXsIndex; index >= 0; index--) {
int Index = mXIndices.get(index);
mXIndices.set(index, Index + 1);
}
int nextIndex = mXPositionIndex + 1;
int nextIndex = mXIndex + 1;
if (nextIndex < mXs.length) {
mdx = 0;
mXPositionIndex = nextIndex;
mXIndex = nextIndex;
String val = mXs[nextIndex];
mx = PropHelper.fromRelativeToFloat(val, mWidth, 0, mScale, fontSize);
}
@@ -258,15 +267,15 @@ class GlyphContext {
}
float nextY() {
for (int index = mYPositionsIndex; index >= 0; index--) {
int positionIndex = mYPositionIndices.get(index);
mYPositionIndices.set(index, positionIndex + 1);
for (int index = mYsIndex; index >= 0; index--) {
int Index = mYIndices.get(index);
mYIndices.set(index, Index + 1);
}
int nextIndex = mYPositionIndex + 1;
int nextIndex = mYIndex + 1;
if (nextIndex < mYs.length) {
mdy = 0;
mYPositionIndex = nextIndex;
mYIndex = nextIndex;
String val = mYs[nextIndex];
my = PropHelper.fromRelativeToFloat(val, mHeight, 0, mScale, fontSize);
}
@@ -275,30 +284,30 @@ class GlyphContext {
}
float nextRotation() {
for (int index = mRotationsIndex; index >= 0; index--) {
int rotationIndex = mRotationIndices.get(index);
mRotationIndices.set(index, rotationIndex + 1);
for (int index = mRsIndex; index >= 0; index--) {
int rotationIndex = mRIndices.get(index);
mRIndices.set(index, rotationIndex + 1);
}
int nextIndex = mRotationIndex + 1;
if (nextIndex < mRotations.length) {
mRotationIndex = nextIndex;
mr = mRotations[nextIndex];
int nextIndex = mRIndex + 1;
if (nextIndex < mRs.length) {
mRIndex = nextIndex;
mr = mRs[nextIndex];
}
return mr;
}
float nextDeltaX() {
for (int index = mDeltaXsIndex; index >= 0; index--) {
int deltaIndex = mDeltaXIndices.get(index);
mDeltaXIndices.set(index, deltaIndex + 1);
for (int index = mdXsIndex; index >= 0; index--) {
int deltaIndex = mdXIndices.get(index);
mdXIndices.set(index, deltaIndex + 1);
}
int nextIndex = mDeltaXIndex + 1;
if (nextIndex < mDeltaXs.length) {
mDeltaXIndex = nextIndex;
float val = mDeltaXs[nextIndex];
int nextIndex = mdXIndex + 1;
if (nextIndex < mdXs.length) {
mdXIndex = nextIndex;
float val = mdXs[nextIndex];
mdx += val * mScale;
}
@@ -306,15 +315,15 @@ class GlyphContext {
}
float nextDeltaY() {
for (int index = mDeltaYsIndex; index >= 0; index--) {
int deltaIndex = mDeltaYIndices.get(index);
mDeltaYIndices.set(index, deltaIndex + 1);
for (int index = mdYsIndex; index >= 0; index--) {
int deltaIndex = mdYIndices.get(index);
mdYIndices.set(index, deltaIndex + 1);
}
int nextIndex = mDeltaYIndex + 1;
if (nextIndex < mDeltaYs.length) {
mDeltaYIndex = nextIndex;
float val = mDeltaYs[nextIndex];
int nextIndex = mdYIndex + 1;
if (nextIndex < mdYs.length) {
mdYIndex = nextIndex;
float val = mdYs[nextIndex];
mdy += val * mScale;
}
@@ -178,6 +178,6 @@ class TextShadowNode extends GroupShadowNode {
@Override
void pushGlyphContext() {
boolean isTextNode = !(this instanceof TextPathShadowNode) && !(this instanceof TSpanShadowNode);
getTextRootGlyphContext().pushContext(this, mFont, mRotate, mDeltaX, mDeltaY, mPositionX, mPositionY, isTextNode);
getTextRootGlyphContext().pushContext(this, mFont, isTextNode, mPositionX, mPositionY, mRotate, mDeltaX, mDeltaY);
}
}