2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "resource-text-requester.h"
20 #include "debug/resource-loader-debug.h"
22 using namespace Dali::Integration;
32 const uint32_t FIRST_VISIBLE_CHAR( 0x21 ); // 0x20 is the white space
34 bool IsVisible(uint32_t code)
36 return !(code < FIRST_VISIBLE_CHAR);
39 // helper to remove invisible characters
40 void RemoveInvisibleCharacters( Integration::TextResourceType::CharacterList& text )
42 Integration::TextResourceType::CharacterList temp;
43 temp.reserve(text.size());
44 for(std::size_t i=0, length= text.size(); i< length; i++)
46 if (IsVisible( text[i].character ))
48 temp.push_back(text[i]);
54 } // Anonymous namespace
56 ResourceTextRequester::ResourceTextRequester( ResourceLoader& resourceLoader )
57 : ResourceRequesterBase( resourceLoader ),
62 ResourceTextRequester::~ResourceTextRequester()
67 void ResourceTextRequester::Pause()
75 void ResourceTextRequester::Resume()
79 mThreadText->Resume();
83 void ResourceTextRequester::LoadResource( Integration::ResourceRequest& request )
85 TextResourceType* textRequest = dynamic_cast<TextResourceType*>(request.GetType());
88 TextResourceType::CharacterList& text(textRequest->mCharacterList);
90 // Remove from stored request
91 RemoveInvisibleCharacters( text );
94 IntrusivePtr<GlyphSet> cachedGlyphs( new GlyphSet() );
95 LoadedResource resource( request.GetId(), request.GetType()->id, cachedGlyphs );
96 mResourceLoader.AddLoadedResource(resource);
101 mThreadText->AddRequest( request, ResourceThreadBase::RequestLoad );
106 ResourcePointer ResourceTextRequester::LoadResourceSynchronously( const Integration::ResourceType& type, const std::string& path )
108 DALI_ASSERT_ALWAYS( false && "Cannot load text synchronously" );
111 LoadStatus ResourceTextRequester::LoadFurtherResources( ResourceRequest& request, LoadedResource partialResource )
115 return RESOURCE_COMPLETELY_LOADED;
118 void ResourceTextRequester::SaveResource(const Integration::ResourceRequest& request )
123 void ResourceTextRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
127 mThreadText->CancelRequest(id);
131 void ResourceTextRequester::CreateThread()
135 mThreadText = new ResourceThreadText( mResourceLoader , TextResourceType::TextQualityHigh );