The VisualUrl object encapsulates the URL string and also resolves the data type
and whether the url is local or remote on creation.
Change-Id: I88cfc98563799d2646bde1911a5e8e90496ffd45
Signed-off-by: David Steele <david.steele@samsung.com>
utc-Dali-VisualModel.cpp
utc-Dali-Text-Layout.cpp
utc-Dali-Text-Controller.cpp
- utc-Dali-VisualFactoryResolveUrl.cpp
+ utc-Dali-VisualUrl.cpp
utc-Dali-Text-Markup.cpp
utc-Dali-Text-Typesetter.cpp
utc-Dali-Text-ViewModel.cpp
+++ /dev/null
-/*
- * Copyright (c) 2016 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.
- *
- */
-
-#include <iostream>
-
-#include <stdlib.h>
-
-#include <dali-toolkit-test-suite-utils.h>
-#include <dali-toolkit/internal/visuals/visual-factory-resolve-url.h>
-
-using namespace Dali::Toolkit::Internal;
-
-int UtcDaliResolveUrlRegularImage(void)
-{
- tet_infoline( "UtcDaliResolveUrl REGULAR_IMAGE" );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.jpeg"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.PNG"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.Png123"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("foobar.Png1.23"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType(""), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType(" "), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("."), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("9"), TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliResolveUrlSvg(void)
-{
- tet_infoline( "UtcDaliResolveUrl SVG" );
-
- DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.svg"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.svg.svg"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.svG"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.SVG"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType(".SvG"), TEST_LOCATION );
-
- // SVGs aren't N-patch
- DALI_TEST_EQUALS( UrlType::SVG, ResolveUrlType("foobar.9.svg"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.png"), TEST_LOCATION );
-
- // maybe controversial, but for now we expect the suffix to be exactly .svg
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.svg1"), TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliResolveUrlNPatch(void)
-{
- tet_infoline( "UtcDaliResolveUrl N_PATCH" );
-
- DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.#.png"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.9.9.bmp"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.9.9.jpg[]=$$"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::N_PATCH, ResolveUrlType("foobar.9.#.#.9.wbpm123"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.##.png"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("svg.99.jpeg"), TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliResolveUrlGif(void)
-{
- tet_infoline( "UtcDaliResolveUrl GIF" );
-
- DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.gif"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.gif.gif"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.giF"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.GIF"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType(".GiF"), TEST_LOCATION );
-
- // GIFs aren't N-patch
- DALI_TEST_EQUALS( UrlType::GIF, ResolveUrlType("foobar.9.gif"), TEST_LOCATION );
-
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("gif.png"), TEST_LOCATION );
- DALI_TEST_EQUALS( UrlType::REGULAR_IMAGE, ResolveUrlType("gif.gif1"), TEST_LOCATION );
-
- END_TEST;
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 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.
+ *
+ */
+
+#include <iostream>
+
+#include <stdlib.h>
+
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
+
+using namespace Dali::Toolkit::Internal;
+
+int UtcDaliVisualUrlConstructor(void)
+{
+ const char* url="http://bar.org/foobar.gif";
+ VisualUrl visualUrl(url);
+ DALI_TEST_EQUALS( true, visualUrl.IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( visualUrl.GetType(), VisualUrl::GIF, TEST_LOCATION );
+ DALI_TEST_EQUALS( visualUrl.GetLocation(), VisualUrl::REMOTE, TEST_LOCATION );
+
+ VisualUrl visualUrl2("foobar.jpeg");
+ visualUrl2 = visualUrl;
+ DALI_TEST_EQUALS( true, visualUrl2.IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( visualUrl2.GetType(), VisualUrl::GIF, TEST_LOCATION );
+ DALI_TEST_EQUALS( visualUrl2.GetLocation(), VisualUrl::REMOTE, TEST_LOCATION );
+
+ VisualUrl visualUrl3( visualUrl );
+ DALI_TEST_EQUALS( true, visualUrl3.IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( visualUrl3.GetType(), VisualUrl::GIF, TEST_LOCATION );
+ DALI_TEST_EQUALS( visualUrl3.GetLocation(), VisualUrl::REMOTE, TEST_LOCATION );
+ END_TEST;
+}
+
+
+int UtcDaliVisualUrlRegularImage(void)
+{
+ tet_infoline( "UtcDaliVisualUrl REGULAR_IMAGE" );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.jpeg").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.PNG").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.Png123").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("foobar.Png1.23").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl(" ").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl(".").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("9").GetType(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliVisualUrlSvg(void)
+{
+ tet_infoline( "UtcDaliVisualUrl SVG" );
+
+ DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.svg").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.svg.svg").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.svG").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.SVG").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl(".SvG").GetType(), TEST_LOCATION );
+
+ // SVGs aren't N-patch
+ DALI_TEST_EQUALS( VisualUrl::SVG, VisualUrl("foobar.9.svg").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.png").GetType(), TEST_LOCATION );
+
+ // maybe controversial, but for now we expect the suffix to be exactly .svg
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.svg1").GetType(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliVisualUrlNPatch(void)
+{
+ tet_infoline( "UtcDaliVisualUrl N_PATCH" );
+
+ DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.#.png").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.9.9.bmp").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.9.9.jpg[]=$$").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::N_PATCH, VisualUrl("foobar.9.#.#.9.wbpm123").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.##.png").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("svg.99.jpeg").GetType(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliVisualUrlGif(void)
+{
+ tet_infoline( "UtcDaliVisualUrl GIF" );
+
+ DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.gif").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.gif.gif").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.giF").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.GIF").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl(".GiF").GetType(), TEST_LOCATION );
+
+ // GIFs aren't N-patch
+ DALI_TEST_EQUALS( VisualUrl::GIF, VisualUrl("foobar.9.gif").GetType(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("gif.png").GetType(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REGULAR_IMAGE, VisualUrl("gif.gif1").GetType(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliVisualUrlLocationP(void)
+{
+ tet_infoline( "UtcDaliVisualUrl Location" );
+
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.jpeg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ftp://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("ssh://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("http://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("https://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("FTP://BAR.ORG/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("SSH://BAR.ORG/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTP://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::REMOTE, VisualUrl("HTTPS://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliVisualUrlLocationN(void)
+{
+ tet_infoline( "UtcDaliVisualUrl Location negative tests" );
+
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("htp://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("htpp://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("sshttp://bar.org/foobar.svg").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("htth://bar.org/foobar.GIF").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("http:https://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("https:http://bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("HPPT://bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("ftp:/bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("ssh;//bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("ssh:/bar.org/foobar.9.png").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("http:/bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("https:/bar.org/foobar.gif").GetLocation(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( VisualUrl::LOCAL, VisualUrl("file://bar.org/foobar.png").GetLocation(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliVisualUrlIsLocal(void)
+{
+ tet_infoline( "UtcDaliVisualUrl IsLocal" );
+
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.gif").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.png").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.svg").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.GIF").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.9.png").IsLocal(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.gif").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.png").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.svg").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("http://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.gif").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.png").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.svg").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("https://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.gif").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.png").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.svg").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTP://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.gif").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.png").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.svg").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.GIF").IsLocal(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("HTTPS://bar.org/foobar.9.png").IsLocal(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliVisualUrlIsValid(void)
+{
+ tet_infoline( "UtcDaliVisualUrl IsValid" );
+
+ DALI_TEST_EQUALS( false, VisualUrl().IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( false, VisualUrl("").IsValid(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.gif").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.png").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.svg").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.GIF").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("foobar.9.png").IsValid(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.gif").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.png").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.svg").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.GIF").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("http://bar.org/foobar.9.png").IsValid(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.gif").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.png").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.svg").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.GIF").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("https://bar.org/foobar.9.png").IsValid(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.gif").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.png").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.svg").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.GIF").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTP://bar.org/foobar.9.png").IsValid(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.gif").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.png").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.svg").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.GIF").IsValid(), TEST_LOCATION );
+ DALI_TEST_EQUALS( true, VisualUrl("HTTPS://bar.org/foobar.9.png").IsValid(), TEST_LOCATION );
+
+ END_TEST;
+}
#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
+
using namespace Dali;
using namespace Toolkit;
PushButton pushButton = PushButton::New();
const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
- const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f );
- const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f);
+ const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
+
+ // Get actual size of test image
+ ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
+ const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
Stage::GetCurrent().Add( pushButton );
- TestPlatformAbstraction& platform = application.GetPlatform();
- platform.SetClosestImageSize( TEST_IMAGE_SIZE );
pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
- const Vector2 expectedIconAndPaddingSize( TEST_ICON_PADDING.x+TEST_ICON_PADDING.y+TEST_IMAGE_SIZE.width, TEST_ICON_PADDING.w+TEST_ICON_PADDING.z +TEST_IMAGE_SIZE.height );
+ const Vector2 expectedIconAndPaddingSize( TEST_ICON_PADDING.x+TEST_ICON_PADDING.y+TEST_IMAGE_SIZE.width, TEST_ICON_PADDING.w + TEST_ICON_PADDING.z + TEST_IMAGE_SIZE.height );
DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
// Now test padding for both label and icon simultaneously.
tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
- DALI_TEST_GREATER( size.height, expectedIconAndPaddingSize.width, TEST_LOCATION ); // Test height of control is greater than icon and padding. As Text set to larger values.
+ // Test height of control is same as icon and padding, as Text is smaller than icon
+ DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
END_TEST;
}
const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
- const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f);
+
+ // Get actual size of test image
+ ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
+ const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
PushButton pushButton = PushButton::New();
const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
- TestPlatformAbstraction& platform = application.GetPlatform();
- platform.SetClosestImageSize( TEST_IMAGE_SIZE );
-
// Add Icon and set its alignment
pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
$(toolkit_src_dir)/builder/style.cpp \
$(toolkit_src_dir)/builder/tree-node-manipulator.cpp \
$(toolkit_src_dir)/builder/replacement.cpp \
- $(toolkit_src_dir)/visuals/visual-base-impl.cpp \
- $(toolkit_src_dir)/visuals/visual-base-data-impl.cpp \
- $(toolkit_src_dir)/visuals/image-atlas-manager.cpp \
- $(toolkit_src_dir)/visuals/npatch-loader.cpp \
- $(toolkit_src_dir)/visuals/visual-factory-cache.cpp \
- $(toolkit_src_dir)/visuals/visual-factory-impl.cpp \
- $(toolkit_src_dir)/visuals/visual-string-constants.cpp \
$(toolkit_src_dir)/visuals/animated-image/animated-image-visual.cpp \
$(toolkit_src_dir)/visuals/border/border-visual.cpp \
$(toolkit_src_dir)/visuals/color/color-visual.cpp \
+ $(toolkit_src_dir)/visuals/gradient/gradient-visual.cpp \
$(toolkit_src_dir)/visuals/gradient/gradient.cpp \
$(toolkit_src_dir)/visuals/gradient/linear-gradient.cpp \
$(toolkit_src_dir)/visuals/gradient/radial-gradient.cpp \
- $(toolkit_src_dir)/visuals/gradient/gradient-visual.cpp \
+ $(toolkit_src_dir)/visuals/image-atlas-manager.cpp \
$(toolkit_src_dir)/visuals/image/image-visual.cpp \
$(toolkit_src_dir)/visuals/mesh/mesh-visual.cpp \
+ $(toolkit_src_dir)/visuals/npatch-loader.cpp \
$(toolkit_src_dir)/visuals/npatch/npatch-visual.cpp \
$(toolkit_src_dir)/visuals/primitive/primitive-visual.cpp \
$(toolkit_src_dir)/visuals/svg/svg-rasterize-thread.cpp \
$(toolkit_src_dir)/visuals/svg/svg-visual.cpp \
$(toolkit_src_dir)/visuals/text/text-visual.cpp \
- $(toolkit_src_dir)/visuals/wireframe/wireframe-visual.cpp \
$(toolkit_src_dir)/visuals/transition-data-impl.cpp \
+ $(toolkit_src_dir)/visuals/visual-base-data-impl.cpp \
+ $(toolkit_src_dir)/visuals/visual-base-impl.cpp \
+ $(toolkit_src_dir)/visuals/visual-factory-cache.cpp \
+ $(toolkit_src_dir)/visuals/visual-factory-impl.cpp \
+ $(toolkit_src_dir)/visuals/visual-string-constants.cpp \
+ $(toolkit_src_dir)/visuals/visual-url.cpp \
+ $(toolkit_src_dir)/visuals/wireframe/wireframe-visual.cpp \
$(toolkit_src_dir)/controls/alignment/alignment-impl.cpp \
$(toolkit_src_dir)/controls/bloom-view/bloom-view-impl.cpp \
$(toolkit_src_dir)/controls/bubble-effect/bubble-emitter-impl.cpp \
}
-AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties )
+AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties )
{
AnimatedImageVisual* visual = new AnimatedImageVisual( factoryCache );
visual->mImageUrl = imageUrl;
return visual;
}
-AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl )
+AnimatedImageVisualPtr AnimatedImageVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl )
{
AnimatedImageVisual* visual = new AnimatedImageVisual( factoryCache );
visual->mImageUrl = imageUrl;
{
if( mImageSize.GetWidth() == 0 && mImageSize.GetHeight() == 0)
{
- mImageSize = Dali::GetGifImageSize( mImageUrl );
+ mImageSize = Dali::GetGifImageSize( mImageUrl.GetUrl() );
}
naturalSize.width = mImageSize.GetWidth();
map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::ANIMATED_IMAGE );
- if( !mImageUrl.empty() )
+ if( mImageUrl.IsValid() )
{
- map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl );
+ map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
}
map.Insert( Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea );
{
// load from image file
std::vector<Dali::PixelData> pixelDataList;
- if( Dali::LoadAnimatedGifFromFile( mImageUrl.c_str() , pixelDataList, mFrameDelayContainer ) )
+
+ if( mImageUrl.IsLocal() )
{
- mImageSize.SetWidth( pixelDataList[0].GetWidth() );
- mImageSize.SetHeight( pixelDataList[0].GetHeight() );
+ if( Dali::LoadAnimatedGifFromFile( mImageUrl.GetUrl().c_str() , pixelDataList, mFrameDelayContainer ) )
+ {
+ mImageSize.SetWidth( pixelDataList[0].GetWidth() );
+ mImageSize.SetHeight( pixelDataList[0].GetHeight() );
- return Toolkit::ImageAtlas::PackToAtlas( pixelDataList, mTextureRectContainer );
+ return Toolkit::ImageAtlas::PackToAtlas( pixelDataList, mTextureRectContainer );
+ }
}
return Texture();
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
namespace Dali
{
* @param[in] properties A Property::Map containing settings for this visual
* @return A smart-pointer to the newly allocated visual.
*/
- static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties );
+ static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
/**
* @brief Create the animated image visual using the image URL.
* @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
* @param[in] imageUrl The URL to animated image resource to use
*/
- static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
+ static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
public: // from Visual
Dali::Vector<Vector4> mTextureRectContainer;
Dali::Vector<uint32_t> mFrameDelayContainer;
Vector4 mPixelArea;
- std::string mImageUrl;
+ VisualUrl mImageUrl;
ImageDimensions mImageSize;
uint32_t mCurrentFrameIndex;
// CLASS HEADER
#include <dali-toolkit/internal/visuals/image/image-visual.h>
-// EXTERNAL HEADER
-#include <cstring> // for strncasecmp
+// EXTERNAL HEADERS
+#include <cstring> // for strlen()
#include <dali/public-api/images/resource-image.h>
#include <dali/public-api/images/native-image.h>
#include <dali/devel-api/images/texture-set-image.h>
#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
#include <dali/devel-api/scripting/enum-helper.h>
#include <dali/devel-api/scripting/scripting.h>
#include <dali/integration-api/debug.h>
-// INTERNAL HEADER
+// INTERNAL HEADERS
#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/internal/visuals/image-atlas-manager.h>
#include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
namespace Dali
{
namespace
{
-const char HTTP_URL[] = "http://";
-const char HTTPS_URL[] = "https://";
// property names
const char * const IMAGE_FITTING_MODE( "fittingMode" );
} // unnamed namespace
ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache,
- const std::string& imageUrl,
+ const VisualUrl& imageUrl,
const Property::Map& properties,
ImageDimensions size,
FittingMode::Type fittingMode,
}
ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache,
- const std::string& imageUrl,
+ const VisualUrl& imageUrl,
ImageDimensions size,
FittingMode::Type fittingMode,
Dali::SamplingMode::Type samplingMode )
}
ImageVisual::ImageVisual( VisualFactoryCache& factoryCache,
- const std::string& imageUrl,
+ const VisualUrl& imageUrl,
ImageDimensions size,
FittingMode::Type fittingMode,
Dali::SamplingMode::Type samplingMode )
}
}
- if( mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING && mImageUrl.size() > 0u )
+ if( mImpl->mFlags & Impl::IS_SYNCHRONOUS_RESOURCE_LOADING && mImageUrl.IsValid() )
{
// if sync loading is required, the loading should start
// immediately when new image url is set or the actor is off stage
naturalSize.y = mDesiredSize.GetHeight();
return;
}
- else if( !mImageUrl.empty() )
+ else if( mImageUrl.IsValid() && mImageUrl.GetLocation() == VisualUrl::LOCAL )
{
- ImageDimensions dimentions = ResourceImage::GetImageSize( mImageUrl );
+ ImageDimensions dimentions = Dali::GetClosestImageSize( mImageUrl.GetUrl() );
naturalSize.x = dimentions.GetWidth();
naturalSize.y = dimentions.GetHeight();
return;
void ImageVisual::LoadResourceSynchronously()
{
- if( !mImageUrl.empty() )
+ if( mImageUrl.IsValid() )
{
- BitmapLoader loader = BitmapLoader::New( mImageUrl, mDesiredSize, mFittingMode, mSamplingMode );
+ BitmapLoader loader = BitmapLoader::New( mImageUrl.GetUrl(), mDesiredSize, mFittingMode, mSamplingMode );
loader.Load();
mPixels = loader.GetPixelData();
}
}
-TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading, bool attemptAtlasing )
+TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing )
{
TextureSet textureSet;
textureRect = FULL_TEXTURE_RECT;
{
if( attemptAtlasing )
{
- textureSet = mFactoryCache.GetAtlasManager()->Add(textureRect, url, mDesiredSize, mFittingMode, true, this );
+ textureSet = mFactoryCache.GetAtlasManager()->Add( textureRect, mImageUrl.GetUrl(), mDesiredSize, mFittingMode, true, this );
mImpl->mFlags |= Impl::IS_ATLASING_APPLIED;
}
if( !textureSet ) // big image, no atlasing or atlasing failed
{
mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
- ResourceImage resourceImage = Dali::ResourceImage::New( url, mDesiredSize, mFittingMode, mSamplingMode );
+ ResourceImage resourceImage = Dali::ResourceImage::New( mImageUrl.GetUrl(), mDesiredSize, mFittingMode, mSamplingMode );
resourceImage.LoadingFinishedSignal().Connect( this, &ImageVisual::OnImageLoaded );
textureSet = TextureSet::New();
TextureSetImage( textureSet, 0u, resourceImage );
return textureSet;
}
-void ImageVisual::InitializeRenderer( const std::string& imageUrl )
+void ImageVisual::InitializeRenderer()
{
- mImageUrl = imageUrl;
mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
- if( !mImpl->mCustomShader &&
- ( strncasecmp( imageUrl.c_str(), HTTP_URL, sizeof(HTTP_URL) -1 ) != 0 ) && // dont atlas remote images
- ( strncasecmp( imageUrl.c_str(), HTTPS_URL, sizeof(HTTPS_URL) -1 ) != 0 ) )
+ if( !mImpl->mCustomShader && mImageUrl.GetLocation() == VisualUrl::LOCAL )
{
bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
Vector4 atlasRect;
// texture set has to be created first as we need to know if atlasing succeeded or not
// when selecting the shader
- TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), true );
+ TextureSet textures = CreateTextureSet( atlasRect, IsSynchronousResourceLoading(), true );
CreateRenderer( textures );
if( mImpl->mFlags & Impl::IS_ATLASING_APPLIED ) // the texture is packed inside atlas
{
// for custom shader or remote image, atlas is not applied
Vector4 atlasRect; // ignored in this case
- TextureSet textures = CreateTextureSet( atlasRect, imageUrl, IsSynchronousResourceLoading(), false );
+ TextureSet textures = CreateTextureSet( atlasRect, IsSynchronousResourceLoading(), false );
CreateRenderer( textures );
}
}
void ImageVisual::DoSetOnStage( Actor& actor )
{
- if( !mImageUrl.empty() )
+ if( mImageUrl.IsValid() )
{
- InitializeRenderer( mImageUrl );
+ InitializeRenderer();
}
else if ( mImage )
{
//If we own the image then make sure we release it when we go off stage
actor.RemoveRenderer( mImpl->mRenderer);
- if( !mImageUrl.empty() )
+ if( mImageUrl.IsValid() )
{
- RemoveFromAtlas(mImageUrl);
+ RemoveFromAtlas( mImageUrl.GetUrl() );
mImage.Reset();
}
bool sync = IsSynchronousResourceLoading();
map.Insert( SYNCHRONOUS_LOADING, sync );
- if( !mImageUrl.empty() )
+ if( mImageUrl.IsValid() )
{
- map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl );
+ map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
map.Insert( Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth() );
map.Insert( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight() );
}
{
map.Clear();
map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::Visual::IMAGE );
- if( !mImageUrl.empty() )
+ if( mImageUrl.IsValid() )
{
map.Insert( Toolkit::ImageVisual::Property::DESIRED_WIDTH, mDesiredSize.GetWidth() );
map.Insert( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, mDesiredSize.GetHeight() );
#include <dali/devel-api/object/weak-handle.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/visual-base-impl.h>
#include <dali-toolkit/devel-api/image-loader/atlas-upload-observer.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
namespace Dali
{
* @return A smart-pointer to the newly allocated visual.
*/
static ImageVisualPtr New( VisualFactoryCache& factoryCache,
- const std::string& imageUrl,
+ const VisualUrl& imageUrl,
const Property::Map& properties,
ImageDimensions size = ImageDimensions(),
FittingMode::Type fittingMode = FittingMode::DEFAULT,
* @return A smart-pointer to the newly allocated visual.
*/
static ImageVisualPtr New( VisualFactoryCache& factoryCache,
- const std::string& imageUrl,
+ const VisualUrl& imageUrl,
ImageDimensions size = ImageDimensions(),
FittingMode::Type fittingMode = FittingMode::DEFAULT,
Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR );
* @param[in] samplingMode The SamplingMode of the resource to load
*/
ImageVisual( VisualFactoryCache& factoryCache,
- const std::string& imageUrl,
+ const VisualUrl& imageUrl,
ImageDimensions size,
FittingMode::Type fittingMode,
Dali::SamplingMode::Type samplingMode );
void ApplyImageToSampler( const Image& image );
/**
- * @brief Initializes the Dali::Renderer from an image url string
- *
- * @param[in] imageUrl The image url string to intialize this ImageVisual from
+ * @brief Initializes the Dali::Renderer from the image url
*/
- void InitializeRenderer( const std::string& imageUrl );
+ void InitializeRenderer();
/**
* @brief Initializes the Dali::Renderer from an image handle
* @param[in] attemptAtlasing If true will attempt atlasing, otherwise create unique texture
* @return the texture set to use
*/
- TextureSet CreateTextureSet( Vector4& textureRect, const std::string& url, bool synchronousLoading, bool attemptAtlasing );
+ TextureSet CreateTextureSet( Vector4& textureRect, bool synchronousLoading, bool attemptAtlasing );
/**
* Callback function of image resource loading succeed
PixelData mPixels;
Vector4 mPixelArea;
WeakHandle<Actor> mPlacementActor;
- std::string mImageUrl;
+ VisualUrl mImageUrl;
Dali::ImageDimensions mDesiredSize;
Dali::FittingMode::Type mFittingMode:3;
/////////////////NPatchVisual////////////////
-NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties )
+NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties )
{
NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
nPatchVisual->mImageUrl = imageUrl;
return nPatchVisual;
}
-NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl )
+NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl )
{
NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
nPatchVisual->mImageUrl = imageUrl;
NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image )
{
NPatchVisualPtr nPatchVisual( new NPatchVisual( factoryCache ) );
- nPatchVisual->mImageUrl = image.GetUrl();
-
+ VisualUrl visualUrl( image.GetUrl() );
+ nPatchVisual->mImageUrl = visualUrl;
return nPatchVisual;
}
{
naturalSize.x = 0u;
naturalSize.y = 0u;
+
// load now if not already loaded
- if( NPatchLoader::UNINITIALIZED_ID == mId )
+ if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocal() )
{
- mId = mLoader.Load( mImageUrl, mBorder );
+ mId = mLoader.Load( mImageUrl.GetUrl(), mBorder );
}
const NPatchLoader::Data* data;
if( mLoader.GetNPatchData( mId, data ) )
void NPatchVisual::DoSetOnStage( Actor& actor )
{
// load when first go on stage
- if( NPatchLoader::UNINITIALIZED_ID == mId )
+ if( NPatchLoader::UNINITIALIZED_ID == mId && mImageUrl.IsLocal() )
{
- mId = mLoader.Load( mImageUrl, mBorder );
+ mId = mLoader.Load( mImageUrl.GetUrl(), mBorder );
}
Geometry geometry = CreateGeometry();
{
map.Clear();
map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::N_PATCH );
- map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl );
+ map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
map.Insert( Toolkit::ImageVisual::Property::BORDER_ONLY, mBorderOnly );
map.Insert( Toolkit::DevelImageVisual::Property::BORDER, mBorder );
}
}
else
{
- DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.c_str() );
+ DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.GetUrl().c_str() );
TextureSet textureSet = TextureSet::New();
mImpl->mRenderer.SetTextures( textureSet );
Image croppedImage = VisualFactoryCache::GetBrokenVisualImage();
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
namespace Dali
{
* @param[in] properties A Property::Map containing settings for this visual
* @return A smart-pointer to the newly allocated visual.
*/
- static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties );
+ static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
/**
* @brief Create an N-patch visual using an image URL.
* @param[in] imageUrl The URL to 9 patch image resource to use
* @return A smart-pointer to the newly allocated visual.
*/
- static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
+ static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
/**
* @brief Create an N-patch visual with a NinePatchImage resource.
private:
NPatchLoader& mLoader; ///< reference to N patch loader for fast access
- std::string mImageUrl; ///< The url to the N patch to load
+ VisualUrl mImageUrl; ///< The url to the N patch to load
std::size_t mId; ///< id of the N patch (from loader/cache)
bool mBorderOnly; ///< if only border is desired
Rect< int > mBorder; ///< The size of the border
namespace Internal
{
-SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties )
+SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties )
{
SvgVisualPtr svgVisual( new SvgVisual( factoryCache ) );
svgVisual->ParseFromUrl( imageUrl );
return svgVisual;
}
-SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl )
+SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl )
{
SvgVisualPtr svgVisual( new SvgVisual( factoryCache ) );
svgVisual->ParseFromUrl( imageUrl );
SvgVisual::SvgVisual( VisualFactoryCache& factoryCache )
: Visual::Base( factoryCache ),
mAtlasRect( FULL_TEXTURE_RECT ),
- mImageUrl(),
+ mImageUrl( ),
mParsedImage( NULL ),
mPlacementActor(),
mVisualSize(Vector2::ZERO)
{
map.Clear();
map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::DevelVisual::SVG );
- if( !mImageUrl.empty() )
+ if( mImageUrl.IsValid() )
{
- map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl );
+ map.Insert( Toolkit::ImageVisual::Property::URL, mImageUrl.GetUrl() );
}
}
// Do nothing
}
-void SvgVisual::ParseFromUrl( const std::string& imageUrl )
+void SvgVisual::ParseFromUrl( const VisualUrl& imageUrl )
{
mImageUrl = imageUrl;
-
- Vector2 dpi = Stage::GetCurrent().GetDpi();
- float meanDpi = (dpi.height + dpi.width) * 0.5f;
- mParsedImage = nsvgParseFromFile( imageUrl.c_str(), UNITS, meanDpi );
+ if( mImageUrl.IsLocal() )
+ {
+ Vector2 dpi = Stage::GetCurrent().GetDpi();
+ float meanDpi = (dpi.height + dpi.width) * 0.5f;
+ mParsedImage = nsvgParseFromFile( mImageUrl.GetUrl().c_str(), UNITS, meanDpi );
+ }
}
void SvgVisual::AddRasterizationTask( const Vector2& size )
// INTERNAL INCLUDES
#include <dali-toolkit/internal/visuals/visual-base-impl.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
struct NSVGimage;
* @param[in] properties A Property::Map containing settings for this visual
* @return A smart-pointer to the newly allocated visual.
*/
- static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties );
+ static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
/**
* @brief Create the SVG Visual using the image URL.
* @param[in] imageUrl The URL to svg resource to use
* @return A smart-pointer to the newly allocated visual.
*/
- static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
+ static SvgVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
public: // from Visual
*
* @param[in] imageUrl The URL of the image to parse the SVG from.
*/
- void ParseFromUrl( const std::string& imageUrl );
+ void ParseFromUrl( const VisualUrl& imageUrl );
/**
* @bried Rasterize the svg with the given size, and add it to the visual.
private:
Vector4 mAtlasRect;
- std::string mImageUrl;
+ VisualUrl mImageUrl;
NSVGimage* mParsedImage;
WeakHandle<Actor> mPlacementActor;
Vector2 mVisualSize;
#include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
#include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
-#include <dali-toolkit/internal/visuals/visual-factory-resolve-url.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
namespace Dali
std::string imageUrl;
if( imageURLValue && imageURLValue->Get( imageUrl ) )
{
- // first resolve url type to know which visual to create
- UrlType::Type type = ResolveUrlType( imageUrl );
- if( UrlType::N_PATCH == type )
- {
- visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
- }
- else if( UrlType::SVG == type )
- {
- visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
- }
- else if( UrlType::GIF == type )
- {
- visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
- }
- else // Regular image
+ VisualUrl visualUrl( imageUrl );
+
+ switch( visualUrl.GetType() )
{
- visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
+ case VisualUrl::N_PATCH:
+ {
+ visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+ break;
+ }
+ case VisualUrl::SVG:
+ {
+ visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+ break;
+ }
+ case VisualUrl::GIF:
+ {
+ visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+ break;
+ }
+ case VisualUrl::REGULAR_IMAGE:
+ {
+ visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+ break;
+ }
}
}
-
break;
}
Visual::BasePtr visualPtr;
// first resolve url type to know which visual to create
- UrlType::Type type = ResolveUrlType( url );
- if( UrlType::N_PATCH == type )
- {
- visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), url );
- }
- else if( UrlType::SVG == type )
- {
- visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url );
- }
- else if( UrlType::GIF == type )
- {
- visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), url );
- }
- else // Regular image
+ VisualUrl visualUrl( url );
+ switch( visualUrl.GetType() )
{
- visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), url, size );
+ case VisualUrl::N_PATCH:
+ {
+ visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl );
+ break;
+ }
+ case VisualUrl::SVG:
+ {
+ visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl );
+ break;
+ }
+ case VisualUrl::GIF:
+ {
+ visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl );
+ break;
+ }
+ case VisualUrl::REGULAR_IMAGE:
+ {
+ visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size );
+ break;
+ }
}
if( mDebugEnabled )
+++ /dev/null
-#ifndef DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H
-#define DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H
-
-/*
- * Copyright (c) 2016 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.
- */
-
-#include <ctype.h>
-
-namespace Dali
-{
-
-namespace Toolkit
-{
-
-namespace Internal
-{
-
-namespace UrlType
-{
- /**
- * The type of the URL based on the string contents
- */
- enum Type
- {
- REGULAR_IMAGE,
- N_PATCH,
- SVG,
- GIF
- };
-}
-
-/**
- * Helper to resolve URL type from the string
- * @param[in] url to check
- * @return UrlType
- */
-inline UrlType::Type ResolveUrlType( const std::string& url )
-{
- // if only one char in string, can only be regular image
- const std::size_t count = url.size();
- if( count > 0 )
- {
- // parsing from the end for better chance of early outs
- enum { SUFFIX, HASH, HASH_DOT } state = SUFFIX;
- char SVG[ 4 ] = { 'g', 'v', 's', '.' };
- char GIF[ 4 ] = { 'f', 'i', 'g', '.' };
- unsigned int svgScore = 0;
- unsigned int gifScore = 0;
- int index = count;
- while( --index >= 0 )
- {
- const char currentChar = url[ index ];
- const std::size_t offsetFromEnd = count - index - 1u;
- if( ( offsetFromEnd < sizeof(SVG) )&&( tolower( currentChar ) == SVG[ offsetFromEnd ] ) )
- {
- // early out if SVG as can't be used in N patch for now
- if( ++svgScore == sizeof(SVG) )
- {
- return UrlType::SVG;
- }
- }
- if( ( offsetFromEnd < sizeof(GIF) )&&( tolower( currentChar ) == GIF[ offsetFromEnd ] ) )
- {
- // early out if GIF
- if( ++gifScore == sizeof(GIF) )
- {
- return UrlType::GIF;
- }
- }
- switch( state )
- {
- case SUFFIX:
- {
- if( '.' == currentChar )
- {
- state = HASH;
- }
- break;
- }
- case HASH:
- {
- if( ( '#' == currentChar ) || ( '9' == currentChar ) )
- {
- state = HASH_DOT;
- }
- else
- {
- // early out, not a valid N/9-patch URL
- return UrlType::REGULAR_IMAGE;
- }
- break;
- }
- case HASH_DOT:
- {
- if( '.' == currentChar )
- {
- return UrlType::N_PATCH;
- }
- else
- {
- // early out, not a valid N/9-patch URL
- return UrlType::REGULAR_IMAGE;
- }
- break;
- }
- }
- }
- }
- // if we got here it is a regular image
- return UrlType::REGULAR_IMAGE;
-}
-
-} // namespace Internal
-
-} // namespace Toolkit
-
-} // namespace Dali
-
-#endif /* DALI_TOOLKIT_VISUAL_FACTORY_URL_RESOLVE_H */
--- /dev/null
+/*
+ * Copyright (c) 2017 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 <dali-toolkit/internal/visuals/visual-url.h>
+
+// EXTERNAL HEADERS
+#include <cstring> // for toupper()
+
+namespace Dali
+{
+namespace Toolkit
+{
+namespace Internal
+{
+
+namespace
+{
+
+VisualUrl::Location ResolveLocation( const std::string& url)
+{
+ const char FTP[] = { 'f', 't', 'p', ':', '/', '/' };
+ const char SSH[] = { 's', 's', 'h', ':', '/', '/' };
+ const char HTTP[] = { 'h', 't', 't', 'p', ':', '/', '/' };
+ const char HTTPS[] = { 'h', 't', 't', 'p', 's', ':', '/', '/' };
+
+ const int MATCH_FTP = 0x01;
+ const int MATCH_SSH = 0x02;
+ const int MATCH_HTTP = 0x04;
+ const int MATCH_HTTPS = 0x08;
+
+ const char* urlCStr = url.c_str();
+ if( url.size() > 6 )
+ {
+ if( urlCStr[3] == ':' || urlCStr[4] == ':' || urlCStr[5] == ':' )
+ {
+ int flags = 0x0F;
+ for( unsigned int i=0; i < sizeof(HTTPS); ++i )
+ {
+ char c = tolower( urlCStr[i] );
+ if( i < sizeof(FTP) && (flags & MATCH_FTP) && c != FTP[i] )
+ {
+ flags &= ~MATCH_FTP;
+ }
+ if( i < sizeof(SSH) && (flags & MATCH_SSH) && c != SSH[i] )
+ {
+ flags &= ~MATCH_SSH;
+ }
+ if( i < sizeof(HTTP) && (flags & MATCH_HTTP) && c != HTTP[i] )
+ {
+ flags &= ~MATCH_HTTP;
+ }
+ if( i < sizeof(HTTPS) && (flags & MATCH_HTTPS) && c != HTTPS[i] )
+ {
+ flags &= ~MATCH_HTTPS;
+ }
+
+ if( (flags & (MATCH_FTP | MATCH_SSH | MATCH_HTTP | MATCH_HTTPS )) == 0 )
+ {
+ break;
+ }
+ }
+
+ if( flags )
+ {
+ return VisualUrl::REMOTE;
+ }
+ }
+ }
+ return VisualUrl::LOCAL;
+}
+
+
+VisualUrl::Type ResolveType( const std::string& url )
+{
+ // if only one char in string, can only be regular image
+ const std::size_t count = url.size();
+ if( count > 0 )
+ {
+ // parsing from the end for better chance of early outs
+ enum { SUFFIX, HASH, HASH_DOT } state = SUFFIX;
+ char SVG[ 4 ] = { 'g', 'v', 's', '.' };
+ char GIF[ 4 ] = { 'f', 'i', 'g', '.' };
+ unsigned int svgScore = 0;
+ unsigned int gifScore = 0;
+ int index = count;
+ while( --index >= 0 )
+ {
+ const char currentChar = url[ index ];
+ const std::size_t offsetFromEnd = count - index - 1u;
+ if( ( offsetFromEnd < sizeof(SVG) )&&( tolower( currentChar ) == SVG[ offsetFromEnd ] ) )
+ {
+ // early out if SVG as can't be used in N patch for now
+ if( ++svgScore == sizeof(SVG) )
+ {
+ return VisualUrl::SVG;
+ }
+ }
+ if( ( offsetFromEnd < sizeof(GIF) )&&( tolower( currentChar ) == GIF[ offsetFromEnd ] ) )
+ {
+ // early out if GIF
+ if( ++gifScore == sizeof(GIF) )
+ {
+ return VisualUrl::GIF;
+ }
+ }
+ switch( state )
+ {
+ case SUFFIX:
+ {
+ if( '.' == currentChar )
+ {
+ state = HASH;
+ }
+ break;
+ }
+ case HASH:
+ {
+ if( ( '#' == currentChar ) || ( '9' == currentChar ) )
+ {
+ state = HASH_DOT;
+ }
+ else
+ {
+ // early out, not a valid N/9-patch URL
+ return VisualUrl::REGULAR_IMAGE;
+ }
+ break;
+ }
+ case HASH_DOT:
+ {
+ if( '.' == currentChar )
+ {
+ return VisualUrl::N_PATCH;
+ }
+ else
+ {
+ // early out, not a valid N/9-patch URL
+ return VisualUrl::REGULAR_IMAGE;
+ }
+ break;
+ }
+ }
+ }
+ }
+ // if we got here it is a regular image
+ return VisualUrl::REGULAR_IMAGE;
+}
+
+}
+
+
+VisualUrl::VisualUrl()
+: mUrl(),
+ mType( VisualUrl::REGULAR_IMAGE ),
+ mLocation( VisualUrl::LOCAL )
+{
+}
+
+VisualUrl::VisualUrl( const std::string& url )
+: mUrl( url ),
+ mType( VisualUrl::REGULAR_IMAGE ),
+ mLocation( VisualUrl::LOCAL )
+{
+ if( ! url.empty() )
+ {
+ mLocation = ResolveLocation( url );
+ mType = ResolveType( url );
+ }
+}
+
+VisualUrl::VisualUrl( const VisualUrl& url )
+: mUrl( url.mUrl ),
+ mType( url.mType ),
+ mLocation( url.mLocation )
+{
+}
+
+VisualUrl& VisualUrl::operator=( const VisualUrl& url )
+{
+ if( &url != this )
+ {
+ mUrl = url.mUrl;
+ mType = url.mType;
+ mLocation = url.mLocation;
+ }
+ return *this;
+}
+
+const std::string& VisualUrl::GetUrl() const
+{
+ return mUrl;
+}
+
+VisualUrl::Type VisualUrl::GetType() const
+{
+ return mType;
+}
+
+VisualUrl::Location VisualUrl::GetLocation() const
+{
+ return mLocation;
+}
+
+bool VisualUrl::IsValid() const
+{
+ return mUrl.size() > 0u;
+}
+
+bool VisualUrl::IsLocal() const
+{
+ return mLocation == VisualUrl::LOCAL;
+}
+
+
+
+} // Internal
+} // Toolkit
+} // Dali
--- /dev/null
+#ifndef DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
+#define DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
+
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include <string>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+class VisualUrl
+{
+public:
+
+ /**
+ * The type of the URL based on the string contents
+ */
+ enum Type
+ {
+ REGULAR_IMAGE,
+ N_PATCH,
+ SVG,
+ GIF
+ };
+
+ enum Location
+ {
+ LOCAL,
+ REMOTE
+ };
+
+ /**
+ * Default Constructor.
+ * Resulting URL is not valid
+ */
+ VisualUrl();
+
+ /**
+ * Constructor.
+ * Determines type of visual and whether the url is local or remote
+ * @param[in] url The URL to store and resolve
+ */
+ VisualUrl( const std::string& url );
+
+ /**
+ * Copy constructor
+ * @param[in] url The VisualUrl to copy
+ */
+ VisualUrl( const VisualUrl& url );
+
+ /**
+ * Assignment operator
+ * @param[in] url The VisualUrl to copy
+ */
+ VisualUrl& operator=( const VisualUrl& url );
+
+ /**
+ * Get the full URL
+ * @return The url
+ */
+ const std::string& GetUrl() const;
+
+ /**
+ * Get the visual type of the URL
+ * @return The visual type of the URL
+ */
+ Type GetType() const;
+
+ /**
+ * Is the URL is local to the device, or remote?
+ * @return the location of the resource
+ */
+ Location GetLocation() const;
+
+ /**
+ * Is the URL valid?
+ * @return true if the URL has length
+ */
+ bool IsValid() const;
+
+ /**
+ * @return true if the location is LOCAL
+ */
+ bool IsLocal() const;
+
+private:
+ std::string mUrl;
+ Type mType;
+ Location mLocation;
+};
+
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif /* DALI_TOOLKIT_INTERNAL_VISUAL_URL_H */