add vertical-text bit to paint (not supported yet)

check-point for using freetype on mac (not enabled yet)



git-svn-id: http://skia.googlecode.com/svn/trunk@2657 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-11-10 15:20:49 +00:00
Родитель a2092aab4b
Коммит 830a23e39b
5 изменённых файлов: 145 добавлений и 7 удалений

Просмотреть файл

@ -283,6 +283,7 @@
[ 'skia_os == "mac"', {
'include_dirs': [
'../include/utils/mac',
'../third_party/freetype/include/**',
],
'sources': [
'../include/core/SkMMapStream.h',
@ -290,7 +291,9 @@
'../src/core/SkMMapStream.cpp',
'../src/ports/SkFontHost_mac_coretext.cpp',
# '../src/ports/SkFontHost_FreeType.cpp',
# '../src/ports/SkFontHost_freetype_mac.cpp',
# '../src/ports/SkFontHost_gamma_none.cpp',
'../src/ports/SkThread_pthread.cpp',
],
'link_settings': {

Просмотреть файл

@ -99,14 +99,15 @@ public:
kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
kVerticalText_Flag = 0x1000,
// experimental/private
kForceAAText_Flag = 0x1000,
kForceAAText_Flag = 0x2000,
// when adding extra flags, note that the fFlags member is specified
// with a bit-width and you'll have to expand it.
kAllFlags = 0x1FFF
kAllFlags = 0x2FFF
};
/** Return the paint's flags. Use the Flag enum to test flag values.
@ -203,6 +204,20 @@ public:
*/
void setAutohinted(bool useAutohinter);
bool isVerticalText() const {
return SkToBool(this->getFlags() & kVerticalText_Flag);
}
/**
* Helper for setting or clearing the kVerticalText_Flag bit in
* setFlags(...).
*
* If this bit is set, then advances are treated as Y values rather than
* X values, and drawText will places its glyphs vertically rather than
* horizontally.
*/
void setVerticalText(bool);
/** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set
@return true if the underlineText bit is set in the paint's flags.
*/
@ -847,7 +862,7 @@ private:
SkColor fColor;
SkScalar fWidth;
SkScalar fMiterLimit;
unsigned fFlags : 13;
unsigned fFlags : 14;
unsigned fTextAlign : 2;
unsigned fCapType : 2;
unsigned fJoinType : 2;

Просмотреть файл

@ -171,13 +171,14 @@ public:
kEmbolden_Flag = 0x80,
kSubpixelPositioning_Flag = 0x100,
kAutohinting_Flag = 0x200,
kVertical_Flag = 0x400,
// these should only ever be set if fMaskFormat is LCD16 or LCD32
kLCD_Vertical_Flag = 0x400, // else Horizontal
kLCD_BGROrder_Flag = 0x800, // else RGB order
kLCD_Vertical_Flag = 0x0800, // else Horizontal
kLCD_BGROrder_Flag = 0x1000, // else RGB order
// experimental
kForceAA_Flag = 0x1000
kForceAA_Flag = 0x2000
};
private:
enum {

Просмотреть файл

@ -203,6 +203,11 @@ void SkPaint::setLinearText(bool doLinearText) {
this->setFlags(SkSetClearMask(fFlags, doLinearText, kLinearText_Flag));
}
void SkPaint::setVerticalText(bool doVertical) {
GEN_ID_INC_EVAL(doVertical != isVerticalText());
this->setFlags(SkSetClearMask(fFlags, doVertical, kVerticalText_Flag));
}
void SkPaint::setUnderlineText(bool doUnderline) {
GEN_ID_INC_EVAL(doUnderline != isUnderlineText());
this->setFlags(SkSetClearMask(fFlags, doUnderline, kUnderlineText_Flag));
@ -1352,6 +1357,9 @@ void SkScalerContext::MakeRec(const SkPaint& paint,
if (paint.isAutohinted()) {
flags |= SkScalerContext::kAutohinting_Flag;
}
if (paint.isVerticalText()) {
flags |= SkScalerContext::kVertical_Flag;
}
#ifdef SK_BUILD_FOR_WIN
if (paint.getFlags() & SkPaint::kForceAAText_Flag) {
flags |= SkScalerContext::kForceAA_Flag;

Просмотреть файл

@ -0,0 +1,111 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkFontHost.h"
#include "SkMMapStream.h"
#include "SkTypefaceCache.h"
#define FONT_PATH "/Library/Fonts/Skia.ttf"
class FTMacTypeface : public SkTypeface {
public:
FTMacTypeface(Style style, uint32_t id, SkStream* stream) : SkTypeface(style, id) {
// we take ownership of the stream
fStream = stream;
}
virtual ~FTMacTypeface() {
fStream->unref();
}
SkStream* fStream;
};
static FTMacTypeface* create_from_path(const char path[]) {
SkStream* stream = new SkMMAPStream(path);
size_t size = stream->getLength();
SkASSERT(size);
FTMacTypeface* tf = new FTMacTypeface(SkTypeface::kNormal,
SkTypefaceCache::NewFontID(),
stream);
SkTypefaceCache::Add(tf, SkTypeface::kNormal);
return tf;
}
static SkTypeface* ref_default_typeface() {
static SkTypeface* gDef;
if (NULL == gDef) {
gDef = create_from_path(FONT_PATH);
}
gDef->ref();
return gDef;
}
///////////////////////////////////////////////////////////////////////////////
SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
const char familyName[],
const void* data, size_t bytelength,
SkTypeface::Style style) {
return ref_default_typeface();
}
SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
SkASSERT(!"SkFontHost::CreateTypefaceFromStream unimplemented");
return NULL;
}
SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
return create_from_path(path);
}
bool SkFontHost::ValidFontID(SkFontID fontID) {
return SkTypefaceCache::FindByID(fontID) != NULL;
}
SkStream* SkFontHost::OpenStream(uint32_t fontID) {
FTMacTypeface* tf = (FTMacTypeface*)SkTypefaceCache::FindByID(fontID);
if (tf) {
tf->fStream->ref();
return tf->fStream;
}
return NULL;
}
size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
int32_t* index) {
if (path) {
strncpy(path, "font", length);
}
if (index) {
*index = 0;
}
return 4;
}
void SkFontHost::Serialize(const SkTypeface*, SkWStream*) {
SkASSERT(!"SkFontHost::Serialize unimplemented");
}
SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
SkASSERT(!"SkFontHost::Deserialize unimplemented");
return NULL;
}
SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
return 0;
}
#include "SkTypeface_mac.h"
SkTypeface* SkCreateTypefaceFromCTFont(CTFontRef fontRef) {
SkASSERT(!"Not supported");
return NULL;
}