-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.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://floralicense.org/license/
-//
-// 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.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ *
+ */
// CLASS HEADER
#include "resource-loader.h"
#include <boost/thread.hpp>
#include <iostream>
#include <fstream>
-#include <set>
#include <queue>
// INTERNAL HEADERS
#include <dali/integration-api/debug.h>
#include <dali/integration-api/resource-cache.h>
#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/common/set-wrapper.h>
#include <dali/public-api/math/vector2.h>
#include "resource-requester-base.h"
#include "resource-bitmap-requester.h"
}
}
- ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
- {
- ResourcePointer ptr;
- ResourceRequesterBase* requester = GetRequester(resourceType.id);
- if( requester )
- {
- ptr = requester->LoadResourceSynchronously( resourceType, resourcePath );
- }
- return ptr;
- }
-
void SaveResource(const ResourceRequest& request)
{
ResourceRequesterBase* requester = GetRequester( request.GetType()->id );
}
}
- void GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2& closestSize )
- {
- ResourceRequesterBase* requester = GetRequester(ResourceBitmap);
- ResourceBitmapRequester* bitmapRequester = dynamic_cast<ResourceBitmapRequester*>(requester);
- if( bitmapRequester != NULL )
- {
- bitmapRequester->GetClosestImageSize( filename, attributes, closestSize );
- }
- }
-
- void GetClosestImageSize( ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2& closestSize )
- {
- ResourceRequesterBase* requester = GetRequester(ResourceBitmap);
- ResourceBitmapRequester* bitmapRequester = dynamic_cast<ResourceBitmapRequester*>(requester);
- if( bitmapRequester != NULL )
- {
- bitmapRequester->GetClosestImageSize( resourceBuffer, attributes, closestSize );
- }
- }
-
void AddPartiallyLoadedResource( LoadedResource& resource)
{
// Lock the LoadedQueue to store the loaded resource
mImpl->LoadResource(request);
}
-ResourcePointer ResourceLoader::LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath)
-{
- return mImpl->LoadResourceSynchronously( resourceType, resourcePath );
-}
-
void ResourceLoader::SaveResource(const ResourceRequest& request)
{
mImpl->SaveResource(request);
return mImpl->IsLoading();
}
-void ResourceLoader::GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2& closestSize )
-{
- mImpl->GetClosestImageSize( filename, attributes, closestSize );
-}
-
-void ResourceLoader::GetClosestImageSize( ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2& closestSize )
-{
- mImpl->GetClosestImageSize( resourceBuffer, attributes, closestSize );
-}
-
-
-std::string ResourceLoader::GetFontFamilyForChars(const TextArray& charsRequested)
+const std::string& ResourceLoader::GetFontFamilyForChars( const Integration::TextArray& charsRequested )
{
return mImpl->mFontController->GetFontFamilyForChars( charsRequested ).first;
}
-bool ResourceLoader::AllGlyphsSupported(const std::string &fontFamily, const std::string &fontStyle, const TextArray& charsRequested)
+bool ResourceLoader::AllGlyphsSupported( const std::string& fontFamily, const std::string& fontStyle, const Integration::TextArray& charsRequested )
{
- return mImpl->mFontController->AllGlyphsSupported( Platform::FontController::StyledFontFamily( fontFamily, fontStyle ), charsRequested);
+ // At this point fontFamily and fontStyle must have been validated.
+ return mImpl->mFontController->AllGlyphsSupported( Platform::FontController::StyledFontFamily( fontFamily, fontStyle ), charsRequested );
}
-bool ResourceLoader::ValidateFontFamilyName(const std::string& fontFamily, const std::string& fontStyle, bool& isDefaultSystemFont, std::string& closestFontFamilyMatch, std::string& closestFontStyleMatch)
+bool ResourceLoader::ValidateFontFamilyName( const std::string& fontFamily,
+ const std::string& fontStyle,
+ bool& isDefaultSystemFontFamily,
+ bool& isDefaultSystemFontStyle,
+ std::string& closestFontFamilyMatch,
+ std::string& closestFontStyleMatch )
{
Platform::FontController::StyledFontFamily closestMatch;
- bool result = mImpl->mFontController->ValidateFontFamilyName( Platform::FontController::StyledFontFamily( fontFamily, fontStyle ), isDefaultSystemFont, closestMatch);
+ bool result = mImpl->mFontController->ValidateFontFamilyName( Platform::FontController::StyledFontFamily( fontFamily, fontStyle ),
+ isDefaultSystemFontFamily,
+ isDefaultSystemFontStyle,
+ closestMatch );
closestFontFamilyMatch = closestMatch.first;
closestFontStyleMatch = closestMatch.second;
return result;
}
-const PixelSize ResourceLoader::GetFontLineHeightFromCapsHeight(const std::string fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight, FT_Library freeType)
+PixelSize ResourceLoader::GetFontLineHeightFromCapsHeight( const std::string& fontFamily, const std::string& fontStyle, CapsHeight capsHeight, FT_Library freeType )
{
+ // At this point fontFamily and fontStyle must have been validated.
+
PixelSize result(0);
if (!fontFamily.empty())
{
- std::string fontFileName = GetFontPath( fontFamily, fontStyle );
+ const std::string& fontFileName = GetFontPath( fontFamily, fontStyle );
SlpFace* slpFace = LoadFontFace(fontFileName, PixelSize(capsHeight), freeType);
if (slpFace)
return result;
}
-std::vector<std::string> ResourceLoader::GetFontList( Dali::Integration::PlatformAbstraction::FontListMode mode )
+void ResourceLoader::GetFontList( Dali::Integration::PlatformAbstraction::FontListMode mode, std::vector<std::string>& fontList )
{
- std::vector<std::string> result;
- std::set<std::string> uniqueFontNames;
-
// VCC TODO: A GetStyles() method which returns a list of styles for a given font family is needed.
- Platform::FontController::FontList fontList;
- Platform::FontController::FontListMode listMode;
+ Platform::FontController::FontListMode listMode = Platform::FontController::LIST_SYSTEM_FONTS;
switch( mode )
{
}
default:
{
- DALI_ASSERT_DEBUG(0 && "invalid mode");
- return result;
+ DALI_ASSERT_DEBUG( false && "invalid mode" );
}
}
- fontList = mImpl->mFontController->GetFontList( listMode );
+ Platform::FontController::FontList styledFontList;
+ mImpl->mFontController->GetFontList( listMode, styledFontList );
- for( Platform::FontController::FontList::const_iterator it = fontList.begin(), endIt = fontList.end(); it != endIt; ++it )
+ std::set<std::string> uniqueFontNames;
+ for( Platform::FontController::FontList::const_iterator it = styledFontList.begin(), endIt = styledFontList.end(); it != endIt; ++it )
{
- uniqueFontNames.insert(it->first);
+ uniqueFontNames.insert( it->first );
}
// copy into a vector
- std::copy(uniqueFontNames.begin(), uniqueFontNames.end(), std::back_inserter(result));
-
- return result;
+ std::copy( uniqueFontNames.begin(), uniqueFontNames.end(), std::back_inserter( fontList ) );
}
const std::string& fontFamily,
bool getBitmap)
{
+ // At this point fontFamily and the font style stored in the textRequest must have been validated.
+
GlyphSet* glyphSet = NULL;
size_t fontHash = textRequest.mFontHash;
// path holds the font name
if( !fontFamily.empty() )
{
- std::string fontFileName = GetFontPath( fontFamily, textRequest.mStyle );
+ const std::string& fontFileName = GetFontPath( fontFamily, textRequest.mStyle );
const bool highQuality(textRequest.mQuality == TextResourceType::TextQualityHigh);
const unsigned int glyphQuality( highQuality ? GlyphMetrics::HIGH_QUALITY : GlyphMetrics::LOW_QUALITY );
glyphMetrics.yPosition = requestedCharacters[n].yPosition;
// create a new bitmap, and copy in the data
- BitmapPtr bitmapData ( Integration::Bitmap::New(Bitmap::BITMAP_2D_PACKED_PIXELS, true) );
- DALI_ASSERT_ALWAYS( data.length == DISTANCE_FIELD_SIZE * DISTANCE_FIELD_SIZE );
+ BitmapPtr bitmapData ( Integration::Bitmap::New(Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD) );
// assign the data
bitmapData->GetPackedPixelsProfile()->AssignBuffer( Pixel::A8, data.data, DISTANCE_FIELD_SIZE * DISTANCE_FIELD_SIZE, DISTANCE_FIELD_SIZE, DISTANCE_FIELD_SIZE );
const std::string& fontStyle,
GlobalMetrics& globalMetrics )
{
- // path holds the font name
+ // At this point fontFamily and fontStyle must have been validated.
+
if( !fontFamily.empty() )
{
- std::string fontFileName = GetFontPath( fontFamily, fontStyle );
+ const std::string& fontFileName = GetFontPath( fontFamily, fontStyle );
SlpFace* slpFace = LoadFontFace( fontFileName, PixelSize( HIGH_QUALITY_PIXEL_SIZE), freeType );
if( slpFace )
return result;
}
-Integration::BitmapPtr ResourceLoader::GetGlyphImage( FT_Library freeType, const std::string& fontFamily, const std::string& fontStyle, const float fontSize, const uint32_t character )
+Integration::BitmapPtr ResourceLoader::GetGlyphImage( FT_Library freeType, const std::string& fontFamily, const std::string& fontStyle, float fontSize, uint32_t character )
{
+ // At this point fontFamily and fontStyle must have been validated.
+
Integration::BitmapPtr image;
- const std::string fontFileName = GetFontPath( fontFamily, fontStyle );
+ const std::string& fontFileName = GetFontPath( fontFamily, fontStyle );
SlpFace* slpFace = LoadFontFace( fontFileName, PixelSize( Font::PointsToPixels( fontSize ) ), freeType );
if( NULL != slpFace )
{
image = GetGlyphBitmap( slpFace->face, character );
+ delete slpFace;
}
return image;
mImpl->mFontController->SetDefaultFontFamily( Platform::FontController::StyledFontFamily( fontFamily, fontStyle ) );
}
-std::string ResourceLoader::GetFontPath(const std::string& fontFamily, const std::string& fontStyle)
+const std::string& ResourceLoader::GetFontPath(const std::string& fontFamily, const std::string& fontStyle)
{
+ // At this point fontFamily and fontStyle must have been validated.
return mImpl->mFontController->GetFontPath(std::make_pair(fontFamily,fontStyle));
}