diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Makefile.am | 1 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 5 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 50 | ||||
-rw-r--r-- | src/core/SkScalar.cpp | 42 | ||||
-rw-r--r-- | src/core/core_files.mk | 1 |
5 files changed, 51 insertions, 48 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 05fc9bb119..4adde0a4c1 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -69,6 +69,7 @@ SkRect.cpp \ SkRefCnt.cpp \ SkRegion.cpp \ SkRegion_path.cpp \ +SkScalar.cpp \ SkScalerContext.cpp \ SkScan.cpp \ SkScan_AntiPath.cpp \ diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 8671d74d70..eff2b32a4c 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -29,6 +29,7 @@ #include "SkShader.h" #include "SkStroke.h" #include "SkTemplatesPriv.h" +#include "SkTextFormatParams.h" #include "SkUtils.h" #include "SkAutoKern.h" @@ -1224,10 +1225,6 @@ void SkDraw::drawText_asPaths(const char text[], size_t byteLength, } } -#define kStdStrikeThru_Offset (-SK_Scalar1 * 6 / 21) -#define kStdUnderline_Offset (SK_Scalar1 / 9) -#define kStdUnderline_Thickness (SK_Scalar1 / 18) - static void draw_paint_rect(const SkDraw* draw, const SkPaint& paint, const SkRect& r, SkScalar textSize) { if (paint.getStyle() == SkPaint::kFill_Style) { diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 21b7534f9b..43a6892049 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -23,8 +23,10 @@ #include "SkPathEffect.h" #include "SkRasterizer.h" #include "SkShader.h" +#include "SkScalar.h" #include "SkScalerContext.h" #include "SkStroke.h" +#include "SkTextFormatParams.h" #include "SkTypeface.h" #include "SkXfermode.h" #include "SkAutoKern.h" @@ -1180,49 +1182,6 @@ static void add_flattenable(SkDescriptor* desc, uint32_t tag, buffer->flatten(desc->addEntry(tag, buffer->size(), NULL)); } -/* - * interpolates to find the right value for key, in the function represented by the 'length' number of pairs: (keys[i], values[i]) - inspired by a desire to change the multiplier for thickness in fakebold - therefore, i assumed number of pairs (length) will be small, so a linear search is sufficient - repeated keys are allowed for discontinuous functions (so long as keys is monotonically increasing), and if - key is the value of a repeated scalar in keys, the first one will be used - - this may change if a binary search is used - - also, this ensures that there is no divide by zero (an assert also checks for that) -*/ -static SkScalar interpolate(SkScalar key, const SkScalar keys[], const SkScalar values[], int length) -{ - - SkASSERT(length > 0); - SkASSERT(keys != NULL); - SkASSERT(values != NULL); -#ifdef SK_DEBUG - for (int i = 1; i < length; i++) - SkASSERT(keys[i] >= keys[i-1]); -#endif - int right = 0; - while (right < length && key > keys[right]) - right++; - //could use sentinal values to eliminate conditionals - //i assume i am not in control of input values, so i want to make it simple - if (length == right) - return values[length-1]; - if (0 == right) - return values[0]; - //otherwise, we interpolate between right-1 and right - SkScalar rVal = values[right]; - SkScalar lVal = values[right-1]; - SkScalar rightKey = keys[right]; - SkScalar leftKey = keys[right-1]; - SkASSERT(rightKey != leftKey); - //fractional amount which we will multiply by the difference in the left value and right value - SkScalar fract = SkScalarDiv(key-leftKey,rightKey-leftKey); - return lVal + SkScalarMul(fract, rVal-lVal); -} - -//used for interpolating in fakeBold -static const SkScalar pointSizes[] = { SkIntToScalar(9), SkIntToScalar(36) }; -static const SkScalar multipliers[] = { SK_Scalar1/24, SK_Scalar1/32 }; - static SkMask::Format computeMaskFormat(const SkPaint& paint) { uint32_t flags = paint.getFlags(); @@ -1284,7 +1243,10 @@ void SkScalerContext::MakeRec(const SkPaint& paint, #ifdef SK_USE_FREETYPE_EMBOLDEN flags |= SkScalerContext::kEmbolden_Flag; #else - SkScalar fakeBoldScale = interpolate(paint.getTextSize(), pointSizes, multipliers, 2); + SkScalar fakeBoldScale = SkScalarInterpFunc(paint.getTextSize(), + kStdFakeBoldInterpKeys, + kStdFakeBoldInterpValues, + kStdFakeBoldInterpLength); SkScalar extra = SkScalarMul(paint.getTextSize(), fakeBoldScale); if (style == SkPaint::kFill_Style) diff --git a/src/core/SkScalar.cpp b/src/core/SkScalar.cpp new file mode 100644 index 0000000000..c6755d1d3c --- /dev/null +++ b/src/core/SkScalar.cpp @@ -0,0 +1,42 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "SkScalar.h" + +SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], + const SkScalar values[], int length) { + SkASSERT(length > 0); + SkASSERT(keys != NULL); + SkASSERT(values != NULL); +#ifdef SK_DEBUG + for (int i = 1; i < length; i++) + SkASSERT(keys[i] >= keys[i-1]); +#endif + int right = 0; + while (right < length && searchKey > keys[right]) + right++; + // Could use sentinel values to eliminate conditionals, but since the + // tables are taken as input, a simpler format is better. + if (length == right) + return values[length-1]; + if (0 == right) + return values[0]; + // Otherwise, interpolate between right - 1 and right. + SkScalar rightKey = keys[right]; + SkScalar leftKey = keys[right-1]; + SkScalar fract = SkScalarDiv(searchKey-leftKey,rightKey-leftKey); + return SkScalarInterp(values[right-1], values[right], fract); +} diff --git a/src/core/core_files.mk b/src/core/core_files.mk index d5cdf39a1c..e84365a7cb 100644 --- a/src/core/core_files.mk +++ b/src/core/core_files.mk @@ -72,6 +72,7 @@ SOURCE := \ SkRefCnt.cpp \ SkRegion.cpp \ SkRegion_path.cpp \ + SkScalar.cpp \ SkScalerContext.cpp \ SkScan.cpp \ SkScan_AntiPath.cpp \ |