AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::CreateEmptyValue (ImplAAFPropertyValue ** ppPropVal) { AAFRESULT result = AAFRESULT_SUCCESS; if (NULL == ppPropVal) return AAFRESULT_NULL_PARAM; ImplAAFTypeDefSP pElementType; result = GetType(&pElementType); if (AAFRESULT_FAILED(result)) return result; if (dynamic_cast<ImplAAFTypeDefStrongObjRef*>((ImplAAFTypeDef*) pElementType)) { // element is strong ref ImplAAFStrongRefArrayValue* pStrongRefArray = NULL; pStrongRefArray = (ImplAAFStrongRefArrayValue*) CreateImpl (CLSID_AAFStrongRefArrayValue); if (!pStrongRefArray) return AAFRESULT_NOMEMORY; result = pStrongRefArray->Initialize(this, kAAFTrue == IsFixedSize()); if (AAFRESULT_SUCCEEDED(result)) { *ppPropVal = pStrongRefArray; } else { pStrongRefArray->ReleaseReference(); } } else if (dynamic_cast<ImplAAFTypeDefWeakObjRef*>((ImplAAFTypeDef*) pElementType)) { // element is weak ref ImplAAFWeakRefArrayValue* pWeakRefArray = NULL; pWeakRefArray = (ImplAAFWeakRefArrayValue*) CreateImpl (CLSID_AAFWeakRefArrayValue); if (!pWeakRefArray) return AAFRESULT_NOMEMORY; result = pWeakRefArray->Initialize(this, kAAFTrue == IsFixedSize()); if (AAFRESULT_SUCCEEDED(result)) { *ppPropVal = pWeakRefArray; } else { pWeakRefArray->ReleaseReference(); } } else { //simply defer to base impl (size is 0) result = CreateValue(ppPropVal); } return result; }
void EFontFT2::GetHeight(e_font_height *height, float size, float shear, bool bold) const { if(!height) return; bzero(height, sizeof(e_font_height)); EAutolock <ELocker> autolock(&etk_ft2_font_locker); if(!IsAttached()) return; bool isfixed = IsFixedSize(size); if(!fScalable && !isfixed) return; if(isfixed ? FT_Set_Pixel_Sizes(fFace, 0, (FT_UInt)size) : FT_Set_Char_Size(fFace, 0, (FT_F26Dot6)(size * 64.f), 0, 0)) return; // if(FT_Set_Pixel_Sizes(fFace, 0, (FT_UInt)size)) return; if(!isfixed) { FT_Fixed scale = fFace->size->metrics.y_scale; height->ascent = (float)(FT_MulFix(fFace->bbox.yMax, scale)) / 64.f; height->descent = -1.f * (float)(FT_MulFix(fFace->bbox.yMin, scale)) / 64.f; height->leading = (float)(FT_MulFix(fFace->height, scale)) / 64.f - height->ascent - height->descent; if(height->leading < 0) height->leading *= -1.f; else height->ascent += height->leading; } else { // TODO height->ascent = size * 0.9f; height->descent = size * 0.1f; height->leading = 0; } }
bool ImplAAFTypeDefCharacter::isFixedSize(void) const { bool result = false; if (IsFixedSize() == kAAFTrue) { result = true; } return result; }
ULONG CMediaType::GetSampleSize() const { if (IsFixedSize()) { return lSampleSize; } else { return 0; } }
float EFontFT2::StringWidth(const char *string, float size, float spacing, float shear, bool bold, eint32 length) const { EAutolock <ELocker> autolock(&etk_ft2_font_locker); if(!IsAttached()) return 0; bool isfixed = IsFixedSize(size); if(!fScalable && !isfixed) return 0; if(isfixed ? FT_Set_Pixel_Sizes(fFace, 0, (FT_UInt)size) : FT_Set_Char_Size(fFace, 0, (FT_F26Dot6)(size * 64.f), 0, 0)) return 0; // if(FT_Set_Pixel_Sizes(fFace, 0, (FT_UInt)size)) return 0; eunichar *unicode = e_utf8_convert_to_unicode(string, length); if(!unicode) return 0; float width = 0; int minx = 0, maxx = 0; const eunichar *ch; int x = 0; int fontSpacing = (int)ceil((double)(spacing * size)) * 64; for(ch = unicode; !(ch == NULL || *ch == 0); ch = e_unicode_next(ch, NULL)) { FT_UInt glyph_index = FT_Get_Char_Index(fFace, *ch); if(FT_Load_Glyph(fFace, glyph_index, FT_LOAD_DEFAULT)) { ETK_DEBUG("[FONT]: %s --- FT_Load_Glyph failed.", __PRETTY_FUNCTION__); continue; } FT_Glyph_Metrics *metrics = &(fFace->glyph->metrics); minx = min_c(minx, x + metrics->horiBearingX); maxx = max_c(maxx, x + max_c(metrics->horiAdvance, metrics->horiBearingX + metrics->width)); x += metrics->horiAdvance + fontSpacing; } if(x > fontSpacing) x -= fontSpacing; width = (float)(maxx - minx) / 64.f; free(unicode); return width; }
euint8* EFontFT2::RenderString(const char *string, eint32 *width, eint32 *height, bool *is_mono, float size, float spacing, float shear, bool bold, eint32 length) { if(string == NULL || *string == 0 || length == 0 || width == NULL || height == NULL || is_mono == NULL) return NULL; EAutolock <ELocker> autolock(&etk_ft2_font_locker); if(!IsAttached()) return NULL; bool isfixed = IsFixedSize(size); if(!fScalable && !isfixed) return NULL; float stringWidth; e_font_height fontHeight; if((stringWidth = StringWidth(string, size, spacing, shear, bold, length)) <= 0) return NULL; GetHeight(&fontHeight, size, shear, bold); eint32 w, h; w = (eint32)ceil(stringWidth) + 1; h = (eint32)ceil(fontHeight.ascent + fontHeight.descent) + 1; euint8 *bitmap = new euint8[w * h]; if(!bitmap) { ETK_WARNING("[FONT]: %s --- Unable to alloc memory for bitmap data.", __PRETTY_FUNCTION__); return NULL; } bzero(bitmap, sizeof(euint8) * (size_t)(w * h)); eunichar *unicode = e_utf8_convert_to_unicode(string, length); if(!unicode) { delete[] bitmap; return NULL; } const eunichar *ch; euint32 x = 0; euint32 y = (euint32)ceil(fontHeight.ascent); bool do_mono = fForceFontAliasing; for(ch = unicode; !(ch == NULL || *ch == 0); ch = e_unicode_next(ch, NULL)) { if(FT_Load_Char(fFace, *ch, (do_mono ? (FT_LOAD_RENDER | FT_LOAD_MONOCHROME) : FT_LOAD_RENDER))) { ETK_DEBUG("[FONT]: %s --- FT_Load_Char failed.", __PRETTY_FUNCTION__); continue; } FT_Bitmap *ftbitmap = &(fFace->glyph->bitmap); eint32 xx = x + (eint32)(fFace->glyph->bitmap_left); eint32 yy = y - (eint32)(fFace->glyph->bitmap_top); eint32 bitmapWidth = (eint32)(ftbitmap->width); eint32 bitmapHeight = (eint32)(ftbitmap->rows); eint32 lineBytes = (eint32)(ftbitmap->pitch > 0 ? ftbitmap->pitch : -(ftbitmap->pitch)); eint32 maxxx = min_c(w, xx + bitmapWidth); eint32 maxyy = min_c(h, yy + bitmapHeight); for(eint32 i = yy, p = 0; i < maxyy; i++, p++) { euint8* dest = bitmap; dest += i * w + xx; unsigned char* src = ftbitmap->buffer; src += p * lineBytes; switch(ftbitmap->pixel_mode) { case FT_PIXEL_MODE_GRAY: for(eint32 j = xx; j < maxxx; j++) *dest++ = (euint8)(*src++); break; case FT_PIXEL_MODE_MONO: for(eint32 j = xx; j < maxxx; ) { euint8 val = (euint8)(*src++); eint32 left = maxxx - j >= 8 ? 8 : maxxx - j; euint8 left_offset = 7; for(eint32 k = 0; k < left; k++, left_offset--, j++) *dest++ = (val & (1 << left_offset)) ? 255 : 0; } break; default: ETK_DEBUG("[FONT]: %s --- The mode of freetype bitmap not supported.", __PRETTY_FUNCTION__); } } x += (euint32)((float)(fFace->glyph->metrics.horiAdvance) / 64.f) + (euint32)ceil((double)(spacing * size)); // next x } free(unicode); *width = w; *height = h; *is_mono = do_mono; return bitmap; }
/* ** Read the common options specified in the ini file. The inherited classes must ** call this base implementation if they overwrite this method. ** */ void Meter::ReadOptions(ConfigParser& parser, const WCHAR* section) { // The MeterStyle defines a template where the values are read if the meter doesn't have it itself const std::wstring& style = parser.ReadString(section, L"MeterStyle", L""); if (!style.empty()) { parser.SetStyleTemplate(style); } Section::ReadOptions(parser, section); BindMeasures(parser, section); int oldX = m_X; std::wstring& x = (std::wstring&)parser.ReadString(section, L"X", L"0"); if (!x.empty()) { WCHAR lastChar = x[x.size() - 1]; if (lastChar == L'r') { m_RelativeX = POSITION_RELATIVE_TL; x.pop_back(); } else if (lastChar == L'R') { m_RelativeX = POSITION_RELATIVE_BR; x.pop_back(); } else { m_RelativeX = POSITION_ABSOLUTE; } m_X = parser.ParseInt(x.c_str(), 0); } else { m_X = 0; m_RelativeX = POSITION_ABSOLUTE; } int oldY = m_Y; std::wstring& y = (std::wstring&)parser.ReadString(section, L"Y", L"0"); if (!y.empty()) { WCHAR lastChar = y[y.size() - 1]; if (lastChar == L'r') { m_RelativeY = POSITION_RELATIVE_TL; y.pop_back(); } else if (lastChar == L'R') { m_RelativeY = POSITION_RELATIVE_BR; y.pop_back(); } else { m_RelativeY = POSITION_ABSOLUTE; } m_Y = parser.ParseInt(y.c_str(), 0); } else { m_Y = 0; m_RelativeY = POSITION_ABSOLUTE; } static const D2D1_RECT_F defPadding = D2D1::RectF(0.0f, 0.0f, 0.0f, 0.0f); m_Padding = parser.ReadRect(section, L"Padding", defPadding); const int oldW = m_W; const bool oldWDefined = m_WDefined; const int widthPadding = GetWidthPadding(); const int w = parser.ReadInt(section, L"W", m_W); m_WDefined = parser.GetLastValueDefined(); if (IsFixedSize(true)) m_W = w; if (!m_Initialized || oldW != (m_W - widthPadding)) m_W += widthPadding; if (!m_WDefined && oldWDefined && IsFixedSize()) { m_W = 0; } const int oldH = m_H; const bool oldHDefined = m_HDefined; const int heightPadding = GetHeightPadding(); const int h = parser.ReadInt(section, L"H", m_H); m_HDefined = parser.GetLastValueDefined(); if (IsFixedSize(true)) m_H = h; if (!m_Initialized || oldH != (m_H - heightPadding)) m_H += heightPadding; if (!m_HDefined && oldHDefined && IsFixedSize()) { m_H = 0; } bool oldHidden = m_Hidden; m_Hidden = parser.ReadBool(section, L"Hidden", false); if (oldX != m_X || oldY != m_Y || oldHidden != m_Hidden) { m_Skin->SetResizeWindowMode(RESIZEMODE_CHECK); // Need to recalculate the window size } m_SolidBevel = (BEVELTYPE)parser.ReadInt(section, L"BevelType", BEVELTYPE_NONE); m_SolidColor = parser.ReadColor(section, L"SolidColor", Gfx::Util::c_Transparent_Color_F); m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor); m_SolidAngle = (FLOAT)parser.ReadFloat(section, L"GradientAngle", 0.0); m_Mouse.ReadOptions(parser, section); m_ToolTipText = parser.ReadString(section, L"ToolTipText", L""); m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L""); m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", L""); m_ToolTipWidth = parser.ReadInt(section, L"ToolTipWidth", 1000); m_ToolTipType = parser.ReadBool(section, L"ToolTipType", false); m_ToolTipHidden = parser.ReadBool(section, L"ToolTipHidden", m_Skin->GetMeterToolTipHidden()); m_AntiAlias = parser.ReadBool(section, L"AntiAlias", false); std::vector<FLOAT> matrix = parser.ReadFloats(section, L"TransformationMatrix"); if (matrix.size() == 6) { m_Transformation = D2D1::Matrix3x2F(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); } else if (!matrix.empty()) { m_Transformation = D2D1::Matrix3x2F::Identity(); LogErrorF(this, L"Meter: Incorrect number of values in TransformationMatrix=%s", parser.ReadString(section, L"TransformationMatrix", L"").c_str()); } ReadContainerOptions(parser, section); }
AAFRESULT STDMETHODCALLTYPE ImplAAFTypeDefArray::SetCArray ( ImplAAFPropertyValue * pPropVal, aafMemPtr_t pData, aafUInt32 dataSize) { if (! pPropVal) return AAFRESULT_NULL_PARAM; if (! pData) return AAFRESULT_NULL_PARAM; if (! IsRegistered ()) return AAFRESULT_NOT_REGISTERED; // Get the property value's embedded type and // check if it's the same as the base type. ImplAAFTypeDefSP pIncomingType; if( AAFRESULT_FAILED( pPropVal->GetType( &pIncomingType ) ) ) return AAFRESULT_BAD_TYPE; ASSERTU (pIncomingType); if( (ImplAAFTypeDef *)pIncomingType != this ) return AAFRESULT_BAD_TYPE; AAFRESULT hr; ImplAAFTypeDefSP pBaseType; hr = GetType (&pBaseType); ASSERTU (pBaseType->IsFixedSize ()); pBaseType->AttemptBuiltinRegistration (); ASSERTU (pBaseType->IsRegistered ()); ImplAAFRefArrayValue* pRefArray = dynamic_cast<ImplAAFRefArrayValue*>(pPropVal); if (NULL != pRefArray) { // This interface is not type-safe for accessing objects! There is also no // mechanism in place to convert between a buffer pointer and an array // of interface pointers; this convertion would not be necessary for // arrays of non-objects. return AAFRESULT_BAD_TYPE; } // Size of individual elements aafUInt32 elemSize = pBaseType->NativeSize (); // number of elements in input data. If this is not an integral // number, this will round down and the test below will fail. aafUInt32 elemCount = dataSize / elemSize; // The size of the new property, calculated from number of elements // and the size of each element. aafUInt32 propSize = elemSize * elemCount; // If the given dataSize was not an integral multiple of the size of // each element, then we'll signal an error. if (propSize != dataSize) return AAFRESULT_BAD_SIZE; // In case of fixed-size arrays, we'll also have to see if the data // size matches what we're expecting. if (IsFixedSize ()) { aafUInt32 nativeSize = NativeSize (); if (nativeSize != dataSize) return AAFRESULT_BAD_SIZE; } ImplAAFPropValData * pvd = 0; ASSERTU (pPropVal); pvd = dynamic_cast<ImplAAFPropValData*> (pPropVal); ASSERTU (pvd); aafMemPtr_t pBits = 0; hr = pvd->AllocateBits (propSize, &pBits); if (AAFRESULT_FAILED (hr)) return hr; ASSERTU (pBits); memcpy (pBits, pData, propSize); return AAFRESULT_SUCCESS; }