lint: format a lot more files

Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
This commit is contained in:
Patrizio Bekerle 2025-04-07 21:34:41 +02:00
parent 9c033736de
commit 097caef2ec
No known key found for this signature in database
GPG key ID: 75960E6926556207
222 changed files with 52271 additions and 62384 deletions

File diff suppressed because it is too large Load diff

View file

@ -8,11 +8,11 @@ option(QON_QT6_BUILD "Build QOwnNotes with Qt6" OFF)
option(DEV_MODE "Build QOwnNotes in developer mode" OFF)
# END options
if (QON_QT6_BUILD)
set(QT_VERSION_MAJOR 6)
set(QT_DEFAULT_MAJOR_VERSION 6)
if(QON_QT6_BUILD)
set(QT_VERSION_MAJOR 6)
set(QT_DEFAULT_MAJOR_VERSION 6)
else()
set(QT_VERSION_MAJOR 5)
set(QT_VERSION_MAJOR 5)
endif()
# put the QOwnNotes.exe in build directory
@ -23,55 +23,52 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# include some Botan settings
add_subdirectory(libraries/botan)
#include sonnet core directory, required for building plugins
# include sonnet core directory, required for building plugins
include_directories(libraries/sonnet/src/core)
#some hunspell settings for windows
# some hunspell settings for windows
include(libraries/sonnet/src/plugins/hunspell/hunspell/CMakeLists.txt)
add_executable(QOwnNotes "")
if (CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug build configuration detected")
add_definitions(-DQT_DEBUG)
if(CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug build configuration detected")
add_definitions(-DQT_DEBUG)
else()
message("Non-debug build configuration detected")
message("Non-debug build configuration detected")
endif()
set_target_properties(QOwnNotes PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
AUTOMOC ON
AUTOUIC ON
AUTORCC ON
)
set_target_properties(
QOwnNotes
PROPERTIES CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
AUTOMOC ON
AUTOUIC ON
AUTORCC ON)
if (UNIX AND DEV_MODE)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(QOwnNotes PRIVATE
-Wall -Wextra -pedantic -Wno-gnu-zero-variadic-macro-arguments -Wno-error=deprecated-declarations
)
else()
target_compile_options(QOwnNotes PRIVATE
-Wall -Wextra -pedantic -Wno-error=deprecated-declarations
)
endif()
if(UNIX AND DEV_MODE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(
QOwnNotes
PRIVATE -Wall -Wextra -pedantic -Wno-gnu-zero-variadic-macro-arguments
-Wno-error=deprecated-declarations)
else()
target_compile_options(QOwnNotes PRIVATE -Wall -Wextra -pedantic
-Wno-error=deprecated-declarations)
endif()
# enable werror on linux
if (NOT APPLE)
message("Werror enabled on linux")
target_compile_options(QOwnNotes PRIVATE -Werror)
endif()
# enable werror on linux
if(NOT APPLE)
message("Werror enabled on linux")
target_compile_options(QOwnNotes PRIVATE -Werror)
endif()
endif()
target_include_directories(QOwnNotes PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
target_include_directories(QOwnNotes PRIVATE ${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_BINARY_DIR})
# Disable shared library building of libraries
set(BUILD_SHARED_LIBS OFF)
# QHotKey library
# Disable building tests inside QHotKey library
# QHotKey library Disable building tests inside QHotKey library
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(QHOTKEY_EXAMPLES OFF)
add_subdirectory(libraries/qhotkey EXCLUDE_FROM_ALL)
@ -79,41 +76,43 @@ add_subdirectory(libraries/qhotkey EXCLUDE_FROM_ALL)
# FakeVim library
set(CREATE_STATIC_LIBRARY ON)
if(MSVC)
add_compile_definitions(FAKEVIM_STATIC_DEFINE QTCREATOR_UTILS_STATIC_LIB)
add_compile_definitions(FAKEVIM_STATIC_DEFINE QTCREATOR_UTILS_STATIC_LIB)
endif()
add_subdirectory(libraries/fakevim EXCLUDE_FROM_ALL)
add_subdirectory(libraries/diff_match_patch EXCLUDE_FROM_ALL)
option(USE_QLITE_HTML "Build using QLiteHtml for preview" OFF)
if (USE_QLITEHTML)
add_definitions(-DUSE_QLITEHTML=1)
add_subdirectory(libraries/qlitehtml EXCLUDE_FROM_ALL)
if(USE_QLITEHTML)
add_definitions(-DUSE_QLITEHTML=1)
add_subdirectory(libraries/qlitehtml EXCLUDE_FROM_ALL)
endif()
message("Using Qt version ${QT_VERSION_MAJOR}")
set(QT_NO_CREATE_VERSIONLESS_FUNCTIONS ON)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED
LinguistTools
Core
Widgets
Gui
Sql
Svg
Network
Xml
PrintSupport
WebSockets
Qml
Concurrent
)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS
REQUIRED
LinguistTools
Core
Widgets
Gui
Sql
Svg
Network
Xml
PrintSupport
WebSockets
Qml
Concurrent)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message(STATUS "ccache found")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message(STATUS "ccache found")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
set(RESOURCE_FILES
@ -126,8 +125,7 @@ set(RESOURCE_FILES
configurations.qrc
libraries/qmarkdowntextedit/media.qrc
libraries/qdarkstyle/style.qrc
libraries/qkeysequencewidget/qkeysequencewidget/qkeysequencewidget.qrc
)
libraries/qkeysequencewidget/qkeysequencewidget/qkeysequencewidget.qrc)
set(SOURCE_FILES
dialogs/welcomedialog.cpp
@ -347,10 +345,8 @@ set(SOURCE_FILES
libraries/fuzzy/kfuzzymatcher.cpp
libraries/qr-code-generator/QrCode.hpp
libraries/qr-code-generator/QrCode.cpp
threads/scriptthread.cpp
threads/scriptthread.h
widgets/qownnotesmarkdowntextedit.cpp
widgets/qownnotesmarkdowntextedit.h
widgets/navigationwidget.cpp
@ -428,71 +424,71 @@ set(SOURCE_FILES
services/websocketserverservice.h
services/webappclientservice.cpp
services/webappclientservice.h
entities/bookmark.h entities/bookmark.cpp
entities/commandsnippet.h entities/commandsnippet.cpp)
entities/bookmark.h
entities/bookmark.cpp
entities/commandsnippet.h
entities/commandsnippet.cpp)
# spellchecker
list(APPEND SOURCE_FILES
libraries/sonnet/src/plugins/hunspell/hunspellclient.cpp
libraries/sonnet/src/plugins/hunspell/hunspellclient.h
libraries/sonnet/src/plugins/hunspell/hunspelldebug.cpp
libraries/sonnet/src/plugins/hunspell/hunspelldebug.h
libraries/sonnet/src/plugins/hunspell/hunspelldict.cpp
libraries/sonnet/src/plugins/hunspell/hunspelldict.h
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affentry.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affentry.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affixmgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affixmgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/atypes.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/baseaffix.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/csutil.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/csutil.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/filemgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/filemgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hashmgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hashmgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/htypes.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunspell.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunspell.h
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunspell.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunvisapi.h
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunvisapi.h.in
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunzip.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunzip.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/langnum.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/phonet.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/phonet.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/replist.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/replist.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/suggestmgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/suggestmgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/utf_info.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/w_char.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/firstparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/firstparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/htmlparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/htmlparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/latexparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/latexparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/manparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/manparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/odfparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/odfparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/textparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/textparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/xmlparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/xmlparser.hxx
)
list(
APPEND
SOURCE_FILES
libraries/sonnet/src/plugins/hunspell/hunspellclient.cpp
libraries/sonnet/src/plugins/hunspell/hunspellclient.h
libraries/sonnet/src/plugins/hunspell/hunspelldebug.cpp
libraries/sonnet/src/plugins/hunspell/hunspelldebug.h
libraries/sonnet/src/plugins/hunspell/hunspelldict.cpp
libraries/sonnet/src/plugins/hunspell/hunspelldict.h
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affentry.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affentry.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affixmgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/affixmgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/atypes.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/baseaffix.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/csutil.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/csutil.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/filemgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/filemgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hashmgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hashmgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/htypes.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunspell.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunspell.h
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunspell.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunvisapi.h
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunvisapi.h.in
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunzip.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/hunzip.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/langnum.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/phonet.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/phonet.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/replist.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/replist.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/suggestmgr.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/suggestmgr.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/utf_info.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/hunspell/w_char.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/firstparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/firstparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/htmlparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/htmlparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/latexparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/latexparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/manparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/manparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/odfparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/odfparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/textparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/textparser.hxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/xmlparser.cxx
libraries/sonnet/src/plugins/hunspell/hunspell/src/parsers/xmlparser.hxx)
# md4c
list(APPEND SOURCE_FILES
libraries/md4c/src/md4c.c
libraries/md4c/src/md4c-html.c
libraries/md4c/src/entity.c
)
list(APPEND SOURCE_FILES libraries/md4c/src/md4c.c
libraries/md4c/src/md4c-html.c libraries/md4c/src/entity.c)
# Translation files
SET(QON_TS_FILES
set(QON_TS_FILES
languages/QOwnNotes_en.ts
languages/QOwnNotes_de.ts
languages/QOwnNotes_fr.ts
@ -557,69 +553,59 @@ SET(QON_TS_FILES
languages/QOwnNotes_bs.ts
languages/QOwnNotes_mk.ts
languages/QOwnNotes_ko.ts
languages/QOwnNotes_et.ts
)
languages/QOwnNotes_et.ts)
if (QON_QT6_BUILD)
qt6_add_translation(QON_QM_FILES ${QON_TS_FILES})
if(QON_QT6_BUILD)
qt6_add_translation(QON_QM_FILES ${QON_TS_FILES})
else()
qt5_add_translation(QON_QM_FILES ${QON_TS_FILES})
qt5_add_translation(QON_QM_FILES ${QON_TS_FILES})
endif()
add_custom_target(translations DEPENDS ${QON_QM_FILES})
target_sources(QOwnNotes PRIVATE
${SOURCE_FILES}
${RESOURCE_FILES}
${QON_QM_FILES}
)
target_sources(QOwnNotes PRIVATE ${SOURCE_FILES} ${RESOURCE_FILES}
${QON_QM_FILES})
# The Qt5::Widgets target will also link Qt::Gui and Qt::Core targets
target_link_libraries(QOwnNotes PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Sql
Qt${QT_VERSION_MAJOR}::Svg
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Xml
Qt${QT_VERSION_MAJOR}::PrintSupport
Qt${QT_VERSION_MAJOR}::WebSockets
Qt${QT_VERSION_MAJOR}::Qml
Qt${QT_VERSION_MAJOR}::Concurrent
QHotkey::QHotkey
Botan::Botan
fakevim
Google::DiffMatchPatch
)
target_link_libraries(
QOwnNotes
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Sql
Qt${QT_VERSION_MAJOR}::Svg
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Xml
Qt${QT_VERSION_MAJOR}::PrintSupport
Qt${QT_VERSION_MAJOR}::WebSockets
Qt${QT_VERSION_MAJOR}::Qml
Qt${QT_VERSION_MAJOR}::Concurrent
QHotkey::QHotkey
Botan::Botan
fakevim
Google::DiffMatchPatch)
if (USE_QLITEHTML)
target_link_libraries(QOwnNotes PRIVATE
qlitehtml::qlitehtml
)
if(USE_QLITEHTML)
target_link_libraries(QOwnNotes PRIVATE qlitehtml::qlitehtml)
endif()
if(MINGW OR MSVC)
# Qt 5 does not define UNICODE for CMake
# only qmake automatically define UNICODE
target_compile_definitions(QOwnNotes PRIVATE
UNICODE _UNICODE
)
# Qt 5 does not define UNICODE for CMake only qmake automatically define
# UNICODE
target_compile_definitions(QOwnNotes PRIVATE UNICODE _UNICODE)
endif()
if(MSVC)
target_compile_definitions(QOwnNotes PRIVATE
NOMINMAX
)
target_compile_definitions(QOwnNotes PRIVATE NOMINMAX)
endif()
add_compile_definitions(QAPPLICATION_CLASS=QApplication)
## Installation
# Installation
install(TARGETS QOwnNotes DESTINATION bin)
install(DIRECTORY images/icons DESTINATION share/icons/hicolor)
install(FILES PBE.QOwnNotes.desktop DESTINATION share/applications)
if (QON_QT6_BUILD)
install(FILES ${QON_QM_FILES} DESTINATION share/qt6/translations)
if(QON_QT6_BUILD)
install(FILES ${QON_QM_FILES} DESTINATION share/qt6/translations)
else()
install(FILES ${QON_QM_FILES} DESTINATION share/qt5/translations)
install(FILES ${QON_QM_FILES} DESTINATION share/qt5/translations)
endif()

View file

@ -6,12 +6,12 @@ Searching system installed Botan 2 library using PkgConfig
#]]
if(MSVC OR MINGW)
message(FATAL_ERROR "Using system Botan 2 library in Window not supported")
message(FATAL_ERROR "Using system Botan 2 library in Window not supported")
endif()
if(TARGET Botan2::Botan2)
message(STATUS "Target Botan::Botan already exists. Skipping searching")
return()
message(STATUS "Target Botan::Botan already exists. Skipping searching")
return()
endif()
find_package(PkgConfig REQUIRED QUIET)

View file

@ -1,15 +1,13 @@
cmake_minimum_required(VERSION 3.5)
project(Botan)
option(BUILD_WITH_SYSTEM_BOTAN "Build using system installed Botan 2 crypto library" OFF)
option(BUILD_WITH_SYSTEM_BOTAN
"Build using system installed Botan 2 crypto library" OFF)
add_library(botan STATIC "")
add_library(Botan::Botan ALIAS botan)
target_sources(botan PRIVATE
botanwrapper.h
botanwrapper.cpp
)
target_sources(botan PRIVATE botanwrapper.h botanwrapper.cpp)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
@ -18,120 +16,82 @@ target_link_libraries(botan PUBLIC Qt${QT_VERSION_MAJOR}::Core)
target_include_directories(botan PUBLIC ${CMAKE_CURRENT_LIST_DIR})
if(BUILD_WITH_SYSTEM_BOTAN)
find_package(Botan2 REQUIRED)
if(NOT TARGET Botan2::Botan2)
message(FATAL_ERROR "Could not find system Botan 2 library using PkgConfig")
endif()
find_package(Botan2 REQUIRED)
if(NOT TARGET Botan2::Botan2)
message(FATAL_ERROR "Could not find system Botan 2 library using PkgConfig")
endif()
target_link_libraries(botan PUBLIC Botan2::Botan2)
target_link_libraries(botan PUBLIC Botan2::Botan2)
target_compile_definitions(botan PUBLIC USE_SYSTEM_BOTAN)
target_compile_definitions(botan PUBLIC USE_SYSTEM_BOTAN)
# Instead of put next lines into else() block
# it is better to just return
return()
# Instead of put next lines into else() block it is better to just return
return()
endif()
target_sources(botan PRIVATE
botan.h
botan.cpp
botan_internal.h
)
target_sources(botan PRIVATE botan.h botan.cpp botan_internal.h)
# add some Botan defines for Linux
if(UNIX)
# Append some definitions as PRIVATE only
# if they used only in cpp and botan_internal header
target_compile_definitions(botan PRIVATE
BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM
)
# Append some definitions as PRIVATE only if they used only in cpp and
# botan_internal header
target_compile_definitions(botan PRIVATE BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_compile_definitions(botan PRIVATE
BOTAN_TARGET_OS_HAS_CLOCK_GETTIME
BOTAN_TARGET_OS_HAS_POSIX_MLOCK
BOTAN_TARGET_OS_HAS_POSIX1
)
target_compile_definitions(
botan PRIVATE BOTAN_TARGET_OS_HAS_CLOCK_GETTIME
BOTAN_TARGET_OS_HAS_POSIX_MLOCK BOTAN_TARGET_OS_HAS_POSIX1)
endif()
if(APPLE)
target_compile_definitions(botan PRIVATE
BOTAN_TARGET_OS_HAS_POSIX1
)
target_compile_definitions(botan PRIVATE BOTAN_TARGET_OS_HAS_POSIX1)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_definitions(botan PUBLIC BOTAN_BUILD_COMPILER_IS_GCC)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_definitions(botan PUBLIC BOTAN_BUILD_COMPILER_IS_CLANG)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
target_compile_definitions(botan PRIVATE BOTAN_BUILD_COMPILER_IS_INTEL)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_definitions(botan PUBLIC BOTAN_BUILD_COMPILER_IS_GCC)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_definitions(botan PUBLIC BOTAN_BUILD_COMPILER_IS_CLANG)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
target_compile_definitions(botan PRIVATE BOTAN_BUILD_COMPILER_IS_INTEL)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i386|i686|x86_64|AMD64)")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
target_compile_definitions(botan PUBLIC
BOTAN_TARGET_CPU_IS_X86_FAMILY
BOTAN_TARGET_ARCH_IS_X86_32
)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
target_compile_definitions(botan PUBLIC
BOTAN_TARGET_CPU_IS_X86_FAMILY
BOTAN_TARGET_ARCH_IS_X86_64
BOTAN_TARGET_CPU_HAS_NATIVE_64BIT
)
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
target_compile_definitions(botan PUBLIC BOTAN_TARGET_CPU_IS_X86_FAMILY
BOTAN_TARGET_ARCH_IS_X86_32)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
target_compile_definitions(
botan PUBLIC BOTAN_TARGET_CPU_IS_X86_FAMILY BOTAN_TARGET_ARCH_IS_X86_64
BOTAN_TARGET_CPU_HAS_NATIVE_64BIT)
endif()
endif()
if(WIN32)
target_compile_definitions(botan PRIVATE
BOTAN_TARGET_OS_IS_WINDOWS
BOTAN_TARGET_OS_HAS_WIN32
BOTAN_HAS_ENTROPY_SRC_WIN32
)
if(MSVC)
# TODO Find analog for:
# QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs
target_compile_options(botan PUBLIC
"-EHs" "-wd4251" "-wd4290" "-wd4250"
)
target_compile_definitions(botan PRIVATE
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
)
target_compile_definitions(botan PUBLIC
BOTAN_BUILD_COMPILER_IS_MSVC
)
if(NOT (MSVC_VERSION LESS 1900))
# For included library binary ABI does not matter
# so disable warning
target_compile_definitions(botan PRIVATE
_ENABLE_EXTENDED_ALIGNED_STORAGE
)
endif()
else()
target_compile_options(botan PRIVATE
"-fpermissive" "-finline-functions" "-Wno-long-long"
)
target_compile_definitions(
botan PRIVATE BOTAN_TARGET_OS_IS_WINDOWS BOTAN_TARGET_OS_HAS_WIN32
BOTAN_HAS_ENTROPY_SRC_WIN32)
if(MSVC)
# TODO Find analog for: QMAKE_CXXFLAGS_EXCEPTIONS_ON = -EHs
target_compile_options(botan PUBLIC "-EHs" "-wd4251" "-wd4290" "-wd4250")
target_compile_definitions(botan PRIVATE _SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS)
target_compile_definitions(botan PUBLIC BOTAN_BUILD_COMPILER_IS_MSVC)
if(NOT (MSVC_VERSION LESS 1900))
# For included library binary ABI does not matter so disable warning
target_compile_definitions(botan PRIVATE _ENABLE_EXTENDED_ALIGNED_STORAGE)
endif()
else()
target_compile_options(botan PRIVATE "-fpermissive" "-finline-functions"
"-Wno-long-long")
endif()
endif()
if(UNIX AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_target_properties(botan PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
target_compile_options(botan PRIVATE
"-fpermissive" "-finline-functions" "-Wno-long-long"
)
set_target_properties(botan PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(botan PRIVATE "-fpermissive" "-finline-functions"
"-Wno-long-long")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "(Linux|FreeBSD)")
target_link_libraries(botan PRIVATE
rt
)
target_compile_definitions(botan PRIVATE
BOTAN_TARGET_OS_HAS_GETAUXVAL
)
target_link_libraries(botan PRIVATE rt)
target_compile_definitions(botan PRIVATE BOTAN_TARGET_OS_HAS_GETAUXVAL)
endif()

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3,16 +3,16 @@
#include <QDebug>
#ifdef USE_SYSTEM_BOTAN
#include <botan/pipe.h>
#include <botan/cipher_mode.h>
#include <botan/base64.h>
#include <botan/cipher_mode.h>
#include <botan/filters.h>
#include <botan/pbkdf2.h>
#include <botan/kdf.h>
#include <botan/hmac.h>
#include <botan/kdf.h>
#include <botan/pbkdf2.h>
#include <botan/pipe.h>
#include <botan/secmem.h>
#include <botan/sha160.h>
#include <botan/types.h>
#include <botan/secmem.h>
#else
#include "botan.h"
#endif
@ -54,16 +54,15 @@ QString BotanWrapper::Encrypt(const QString &Data) {
mSalt.data();
// Create the master key
Botan::SecureVector<Botan::byte> mMaster = pbkdf2.derive_key(
48,
mPassword.toStdString(),
&mSalt[0], mSalt.size(),
PBKDF2_ITERATIONS).bits_of();
Botan::SecureVector<Botan::byte> mMaster =
pbkdf2
.derive_key(48, mPassword.toStdString(), &mSalt[0], mSalt.size(), PBKDF2_ITERATIONS)
.bits_of();
Botan::SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1");
Botan::InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2");
Botan::Pipe pipe(get_cipher("AES-256/CBC/PKCS7", mKey, mIV, Botan::ENCRYPTION),
new Botan::Base64_Encoder);
new Botan::Base64_Encoder);
pipe.process_msg(Data.toStdString());
QString Value = QString::fromStdString(pipe.read_all_as_string(0));
return Value;
@ -75,29 +74,27 @@ QString BotanWrapper::Encrypt(const QString &Data) {
QString BotanWrapper::Decrypt(const QString &Data) {
try {
//Setup the key derive functions
// Setup the key derive functions
Botan::PKCS5_PBKDF2 pbkdf2(new Botan::HMAC(new Botan::SHA_160));
const uint32_t PBKDF2_ITERATIONS = 8192;
//Create the KEY and IV
// Create the KEY and IV
Botan::KDF *kdf = Botan::get_kdf("KDF2(SHA-1)");
//Create the master key
Botan::SecureVector<Botan::byte> mMaster = pbkdf2.derive_key(
48,
mPassword.toStdString(),
&mSalt[0], mSalt.size(),
PBKDF2_ITERATIONS).bits_of();
// Create the master key
Botan::SecureVector<Botan::byte> mMaster =
pbkdf2
.derive_key(48, mPassword.toStdString(), &mSalt[0], mSalt.size(), PBKDF2_ITERATIONS)
.bits_of();
Botan::SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1");
Botan::InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2");
Botan::Pipe pipe(new Botan::Base64_Decoder,
get_cipher("AES-256/CBC/PKCS7", mKey, mIV, Botan::DECRYPTION));
get_cipher("AES-256/CBC/PKCS7", mKey, mIV, Botan::DECRYPTION));
pipe.process_msg(Data.toStdString());
QString Value = QString::fromStdString(pipe.read_all_as_string(0));
return Value;
}
catch (Botan::Exception &e) {
} catch (Botan::Exception &e) {
qWarning() << "[Botan Error] " << e.what();
return QString();
}
@ -111,8 +108,7 @@ void BotanWrapper::setPassword(const QString &Password) {
void BotanWrapper::setSalt(const QString &Salt) {
QByteArray cBytes = Salt.toLatin1();
if (cBytes.size() > 48)
cBytes.resize(48);
if (cBytes.size() > 48) cBytes.resize(48);
mSalt.fill(0);
std::copy(cBytes.cbegin(), cBytes.cend(), mSalt.begin());

View file

@ -4,44 +4,43 @@
#include <QString>
#include <QVector>
class BotanWrapper
{
public:
class BotanWrapper {
public:
BotanWrapper();
/*!
* Creates a hash
* @param Data The string to hash
*/
* Creates a hash
* @param Data The string to hash
*/
QString Hash(const QString &Data);
/*!
* Returns a Base64 encrypted QString
* @param Data The string to encypt
*/
* Returns a Base64 encrypted QString
* @param Data The string to encypt
*/
QString Encrypt(const QString &Data);
/*!
* Returns a decrypted string from a Base64 encypted string
* @param Data The string to encypt
*/
* Returns a decrypted string from a Base64 encypted string
* @param Data The string to encypt
*/
QString Decrypt(const QString &Data);
/*!
* Sets the Password
* @param Password The password
*/
* Sets the Password
* @param Password The password
*/
void setPassword(const QString &Password);
/*!
* Sets the Salt
* @param Salt The salt value
*/
* Sets the Salt
* @param Salt The salt value
*/
void setSalt(const QString &Salt);
private:
private:
QVector<uint8_t> mSalt;
QString mPassword;
};
#endif // BOTANWRAPPER_H
#endif // BOTANWRAPPER_H

View file

@ -1,19 +1,12 @@
cmake_minimum_required(VERSION 3.5)
project(DiffMatchPatchLib)
add_library(diff_match_patch STATIC
diff_match_patch.h
diff_match_patch.cpp
)
add_library(diff_match_patch STATIC diff_match_patch.h diff_match_patch.cpp)
add_library(Google::DiffMatchPatch ALIAS diff_match_patch)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
target_include_directories(diff_match_patch PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
target_include_directories(diff_match_patch PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(diff_match_patch PUBLIC
Qt${QT_VERSION_MAJOR}::Core
)
target_link_libraries(diff_match_patch PUBLIC Qt${QT_VERSION_MAJOR}::Core)

View file

@ -5,20 +5,13 @@ project(fakevim VERSION 0.0.1)
set(bin fakevim)
# Public headers
set(${bin}_public_headers
fakevim/fakevimactions.h
fakevim/fakevimhandler.h
)
set(${bin}_public_headers fakevim/fakevimactions.h fakevim/fakevimhandler.h)
# Source files common for all platforms
set(${bin}_sources
fakevim/fakevimactions.cpp
fakevim/fakevimhandler.cpp
fakevim/utils/hostosinfo.cpp
fakevim/utils/osspecificaspects.h
fakevim/utils/qtcassert.cpp
${${bin}_public_headers}
)
fakevim/fakevimactions.cpp fakevim/fakevimhandler.cpp
fakevim/utils/hostosinfo.cpp fakevim/utils/osspecificaspects.h
fakevim/utils/qtcassert.cpp ${${bin}_public_headers})
# Required pkg-config packages
set(${bin}_pkg_config_requires)
@ -30,49 +23,42 @@ include(cmake/pkg-config.cmake)
# Files with Q_OBJECT macros to pass to moc utility
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if (QT_VERSION_MAJOR EQUAL 6)
qt6_wrap_cpp(${bin}_mocced "fakevim/fakevimhandler.h")
if(QT_VERSION_MAJOR EQUAL 6)
qt6_wrap_cpp(${bin}_mocced "fakevim/fakevimhandler.h")
else()
qt5_wrap_cpp(${bin}_mocced "fakevim/fakevimhandler.h")
qt5_wrap_cpp(${bin}_mocced "fakevim/fakevimhandler.h")
endif()
target_sources(${bin} PRIVATE ${${bin}_mocced})
target_compile_definitions(${bin} PRIVATE
QT_NO_CAST_TO_ASCII
QT_RESTRICTED_CAST_FROM_ASCII
QTCREATOR_UTILS_STATIC_LIB
)
target_compile_definitions(
${bin} PRIVATE QT_NO_CAST_TO_ASCII QT_RESTRICTED_CAST_FROM_ASCII
QTCREATOR_UTILS_STATIC_LIB)
option(BUILD_TESTS "Build tests")
if (BUILD_TESTS)
message(STATUS "Building tests")
if(BUILD_TESTS)
message(STATUS "Building tests")
find_package(Qt5Test REQUIRED)
find_package(Qt5Test REQUIRED)
add_executable(fakevim_test
tests/fakevim_test.cpp
tests/fakevimplugin.h
example/editor.cpp
)
set_property(TARGET fakevim_test PROPERTY AUTOMOC ON)
target_link_libraries(fakevim_test fakevim Qt5::Widgets Qt5::Test)
add_executable(fakevim_test tests/fakevim_test.cpp tests/fakevimplugin.h
example/editor.cpp)
set_property(TARGET fakevim_test PROPERTY AUTOMOC ON)
target_link_libraries(fakevim_test fakevim Qt5::Widgets Qt5::Test)
target_include_directories(fakevim_test PRIVATE
${CMAKE_SOURCE_DIR}/fakevim
${CMAKE_SOURCE_DIR}
)
target_include_directories(fakevim_test PRIVATE ${CMAKE_SOURCE_DIR}/fakevim
${CMAKE_SOURCE_DIR})
add_test(fakevim_test fakevim_test)
enable_testing()
add_test(fakevim_test fakevim_test)
enable_testing()
endif()
option(BUILD_EXAMPLE "Build example")
if (BUILD_EXAMPLE)
message(STATUS "Building example")
if(BUILD_EXAMPLE)
message(STATUS "Building example")
add_executable(fakevim_example example/main.cpp example/editor.cpp)
set_property(TARGET fakevim_example PROPERTY AUTOMOC ON)
add_executable(fakevim_example example/main.cpp example/editor.cpp)
set_property(TARGET fakevim_example PROPERTY AUTOMOC ON)
target_link_libraries(fakevim_example fakevim)
target_link_libraries(fakevim_example Qt5::Widgets)
target_link_libraries(fakevim_example fakevim)
target_link_libraries(fakevim_example Qt5::Widgets)
endif()

View file

@ -1,5 +1,5 @@
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
set(CMAKE_CXX_STANDARD 17)
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.1)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()

View file

@ -1,83 +1,71 @@
set(INSTALL_LIB_DIR "lib${LIB_SUFFIX}" CACHE PATH
"Installation directory for libraries")
set(INSTALL_BIN_DIR "bin" CACHE PATH
"Installation directory for executables")
set(INSTALL_INCLUDE_DIR "include/${bin}" CACHE PATH
"Installation directory for header files")
set(INSTALL_CMAKE_DIR "lib${LIB_SUFFIX}/cmake/${bin}" CACHE PATH
"Installation directory for CMake files")
set(INSTALL_LIB_DIR
"lib${LIB_SUFFIX}"
CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR
"bin"
CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR
"include/${bin}"
CACHE PATH "Installation directory for header files")
set(INSTALL_CMAKE_DIR
"lib${LIB_SUFFIX}/cmake/${bin}"
CACHE PATH "Installation directory for CMake files")
# Shared or static library
option(CREATE_STATIC_LIBRARY "Create static library" OFF)
if (CREATE_STATIC_LIBRARY)
set(libtype STATIC)
if(CREATE_STATIC_LIBRARY)
set(libtype STATIC)
else()
set(libtype SHARED)
set(libtype SHARED)
endif()
add_library(${bin} ${libtype} ${${bin}_sources})
set_target_properties(${bin} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
set_target_properties(${bin} PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
# Headers
set(export_header "${CMAKE_CURRENT_BINARY_DIR}/private/${bin}_export.h")
set_target_properties(${bin} PROPERTIES
PUBLIC_HEADER "${${bin}_public_headers}"
PRIVATE_HEADER "${export_header}")
set_target_properties(${bin} PROPERTIES PUBLIC_HEADER "${${bin}_public_headers}"
PRIVATE_HEADER "${export_header}")
target_include_directories(${bin}
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${bin}>
INTERFACE $<INSTALL_INTERFACE:include/${bin}>
)
target_include_directories(
${bin}
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${bin}>
INTERFACE $<INSTALL_INTERFACE:include/${bin}>)
install(
TARGETS ${bin} EXPORT ${bin}Targets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}" COMPONENT dev
PRIVATE_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/private" COMPONENT dev
)
TARGETS ${bin}
EXPORT ${bin}Targets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}" COMPONENT dev
PRIVATE_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/private" COMPONENT dev)
# Generate and install CMake files for the library so `find_package(<Library>)` can be used with CMake.
# For more info: https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#creating-packages
# Generate and install CMake files for the library so `find_package(<Library>)`
# can be used with CMake. For more info:
# https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#creating-packages
include(GenerateExportHeader)
generate_export_header(${bin} EXPORT_FILE_NAME "${export_header}")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${bin}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
"${CMAKE_CURRENT_BINARY_DIR}/${bin}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
export(
EXPORT ${bin}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${bin}Targets.cmake"
)
configure_file(
cmake/${bin}Config.cmake
"${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake"
COPYONLY
)
export(EXPORT ${bin}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${bin}Targets.cmake")
configure_file(cmake/${bin}Config.cmake
"${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake" COPYONLY)
install(
EXPORT ${bin}Targets
FILE
${bin}Targets.cmake
DESTINATION
"${INSTALL_CMAKE_DIR}"
COMPONENT
dev
)
EXPORT ${bin}Targets
FILE ${bin}Targets.cmake
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake"
FILES "${CMAKE_CURRENT_BINARY_DIR}/${bin}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${bin}ConfigVersion.cmake"
DESTINATION
"${INSTALL_CMAKE_DIR}"
COMPONENT
dev
)
DESTINATION "${INSTALL_CMAKE_DIR}"
COMPONENT dev)

View file

@ -4,19 +4,14 @@ set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/${bin}")
set(PKG_CONFIG_LIBS "-L\${libdir} -l${bin}")
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
#configure_file(
# "${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.in"
# "${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc"
# )
# configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.in"
# "${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc" )
set(INSTALL_PKG_CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig"
set(INSTALL_PKG_CONFIG_DIR
"${CMAKE_INSTALL_PREFIX}/lib/pkgconfig"
CACHE PATH "Installation directory for pkg-config files")
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc"
DESTINATION
"${INSTALL_PKG_CONFIG_DIR}"
COMPONENT
dev
)
FILES "${CMAKE_CURRENT_BINARY_DIR}/${bin}.pc"
DESTINATION "${INSTALL_PKG_CONFIG_DIR}"
COMPONENT dev)

View file

@ -3,4 +3,5 @@ find_package(Qt${QT_VERSION_MAJOR}Widgets REQUIRED)
# include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
target_link_libraries(${bin} Qt${QT_VERSION_MAJOR}::Widgets)
set(${bin}_pkg_config_requires ${${bin}_pkg_config_requires} Qt${QT_VERSION_MAJOR}::Widgets)
set(${bin}_pkg_config_requires ${${bin}_pkg_config_requires}
Qt${QT_VERSION_MAJOR}::Widgets)

View file

@ -24,6 +24,7 @@
****************************************************************************/
#include "fakevimactions.h"
#include "fakevimhandler.h"
// Please do not add any direct dependencies to other Qt Creator code here.
@ -41,80 +42,62 @@ namespace FakeVim {
namespace Internal {
#ifdef FAKEVIM_STANDALONE
FvBaseAspect::FvBaseAspect()
{
}
FvBaseAspect::FvBaseAspect() {}
void FvBaseAspect::setValue(const QVariant &value)
{
m_value = value;
}
void FvBaseAspect::setValue(const QVariant &value) { m_value = value; }
QVariant FvBaseAspect::value() const
{
return m_value;
}
QVariant FvBaseAspect::value() const { return m_value; }
void FvBaseAspect::setDefaultValue(const QVariant &value)
{
void FvBaseAspect::setDefaultValue(const QVariant &value) {
m_defaultValue = value;
m_value = value;
}
QVariant FvBaseAspect::defaultValue() const
{
return m_defaultValue;
}
QVariant FvBaseAspect::defaultValue() const { return m_defaultValue; }
void FvBaseAspect::setSettingsKey(const QString &group, const QString &key)
{
void FvBaseAspect::setSettingsKey(const QString &group, const QString &key) {
m_settingsGroup = group;
m_settingsKey = key;
}
QString FvBaseAspect::settingsKey() const
{
return m_settingsKey;
}
QString FvBaseAspect::settingsKey() const { return m_settingsKey; }
#endif
FakeVimSettings::FakeVimSettings()
{
FakeVimSettings::FakeVimSettings() {
#ifndef FAKEVIM_STANDALONE
setup(&useFakeVim, false, "UseFakeVim", {}, tr("Use FakeVim"));
setup(&useFakeVim, false, "UseFakeVim", {}, tr("Use FakeVim"));
#endif
// Specific FakeVim settings
setup(&readVimRc, false, "ReadVimRc", {}, tr("Read .vimrc from location:"));
setup(&vimRcPath, QString(), "VimRcPath", {}, {}); // tr("Path to .vimrc")
setup(&showMarks, false, "ShowMarks", "sm", tr("Show position of text marks"));
setup(&readVimRc, false, "ReadVimRc", {}, tr("Read .vimrc from location:"));
setup(&vimRcPath, QString(), "VimRcPath", {}, {}); // tr("Path to .vimrc")
setup(&showMarks, false, "ShowMarks", "sm", tr("Show position of text marks"));
setup(&passControlKey, false, "PassControlKey", "pck", tr("Pass control keys"));
setup(&passKeys, true, "PassKeys", "pk", tr("Pass keys in insert mode"));
setup(&passKeys, true, "PassKeys", "pk", tr("Pass keys in insert mode"));
// Emulated Vsetting
setup(&startOfLine, true, "StartOfLine", "sol", tr("Start of line"));
setup(&tabStop, 8, "TabStop", "ts", tr("Tabulator size:"));
setup(&smartTab, false, "SmartTab", "sta", tr("Smart tabulators"));
setup(&hlSearch, true, "HlSearch", "hls", tr("Highlight search results"));
setup(&shiftWidth, 8, "ShiftWidth", "sw", tr("Shift width:"));
setup(&expandTab, false, "ExpandTab", "et", tr("Expand tabulators"));
setup(&autoIndent, false, "AutoIndent", "ai", tr("Automatic indentation"));
setup(&smartIndent, false, "SmartIndent", "si", tr("Smart tabulators"));
setup(&incSearch, true, "IncSearch", "is", tr("Incremental search"));
setup(&useCoreSearch, false, "UseCoreSearch", "ucs", tr("Use search dialog"));
setup(&smartCase, false, "SmartCase", "scs", tr("Use smartcase"));
setup(&ignoreCase, false, "IgnoreCase", "ic", tr("Use ignorecase"));
setup(&wrapScan, true, "WrapScan", "ws", tr("Use wrapscan"));
setup(&tildeOp, false, "TildeOp", "top", tr("Use tildeop"));
setup(&showCmd, true, "ShowCmd", "sc", tr("Show partial command"));
setup(&relativeNumber, false, "RelativeNumber", "rnu", tr("Show line numbers relative to cursor"));
setup(&blinkingCursor, false, "BlinkingCursor", "bc", tr("Blinking cursor"));
setup(&scrollOff, 0, "ScrollOff", "so", tr("Scroll offset:"));
setup(&backspace, "indent,eol,start",
"Backspace", "bs", tr("Backspace:"));
setup(&isKeyword, "@,48-57,_,192-255,a-z,A-Z",
"IsKeyword", "isk", tr("Keyword characters:"));
setup(&clipboard, {}, "Clipboard", "cb", tr(""));
setup(&formatOptions, {}, "formatoptions", "fo", tr(""));
setup(&startOfLine, true, "StartOfLine", "sol", tr("Start of line"));
setup(&tabStop, 8, "TabStop", "ts", tr("Tabulator size:"));
setup(&smartTab, false, "SmartTab", "sta", tr("Smart tabulators"));
setup(&hlSearch, true, "HlSearch", "hls", tr("Highlight search results"));
setup(&shiftWidth, 8, "ShiftWidth", "sw", tr("Shift width:"));
setup(&expandTab, false, "ExpandTab", "et", tr("Expand tabulators"));
setup(&autoIndent, false, "AutoIndent", "ai", tr("Automatic indentation"));
setup(&smartIndent, false, "SmartIndent", "si", tr("Smart tabulators"));
setup(&incSearch, true, "IncSearch", "is", tr("Incremental search"));
setup(&useCoreSearch, false, "UseCoreSearch", "ucs", tr("Use search dialog"));
setup(&smartCase, false, "SmartCase", "scs", tr("Use smartcase"));
setup(&ignoreCase, false, "IgnoreCase", "ic", tr("Use ignorecase"));
setup(&wrapScan, true, "WrapScan", "ws", tr("Use wrapscan"));
setup(&tildeOp, false, "TildeOp", "top", tr("Use tildeop"));
setup(&showCmd, true, "ShowCmd", "sc", tr("Show partial command"));
setup(&relativeNumber, false, "RelativeNumber", "rnu",
tr("Show line numbers relative to cursor"));
setup(&blinkingCursor, false, "BlinkingCursor", "bc", tr("Blinking cursor"));
setup(&scrollOff, 0, "ScrollOff", "so", tr("Scroll offset:"));
setup(&backspace, "indent,eol,start", "Backspace", "bs", tr("Backspace:"));
setup(&isKeyword, "@,48-57,_,192-255,a-z,A-Z", "IsKeyword", "isk", tr("Keyword characters:"));
setup(&clipboard, {}, "Clipboard", "cb", tr(""));
setup(&formatOptions, {}, "formatoptions", "fo", tr(""));
// Emulated plugins
setup(&emulateVimCommentary, false, "commentary", {}, "vim-commentary");
@ -126,15 +109,18 @@ FakeVimSettings::FakeVimSettings()
// Some polish
useFakeVim.setDisplayName(tr("Use Vim-style Editing"));
relativeNumber.setToolTip(tr("Displays line numbers relative to the line containing "
"text cursor."));
relativeNumber.setToolTip(
tr("Displays line numbers relative to the line containing "
"text cursor."));
passControlKey.setToolTip(tr("Does not interpret key sequences like Ctrl-S in FakeVim "
"but handles them as regular shortcuts. This gives easier access to core functionality "
"at the price of losing some features of FakeVim."));
passControlKey.setToolTip(
tr("Does not interpret key sequences like Ctrl-S in FakeVim "
"but handles them as regular shortcuts. This gives easier access to core functionality "
"at the price of losing some features of FakeVim."));
passKeys.setToolTip(tr("Does not interpret some key presses in insert mode so that "
"code can be properly completed and expanded."));
passKeys.setToolTip(
tr("Does not interpret some key presses in insert mode so that "
"code can be properly completed and expanded."));
tabStop.setToolTip(tr("Vim tabstop option."));
@ -142,11 +128,12 @@ FakeVimSettings::FakeVimSettings()
backspace.setDisplayStyle(FvStringAspect::LineEditDisplay);
isKeyword.setDisplayStyle(FvStringAspect::LineEditDisplay);
const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
const QString vimrcDefault =
QLatin1String(HostOsInfo::isAnyUnixHost() ? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
vimRcPath.setExpectedKind(PathChooser::File);
vimRcPath.setToolTip(tr("Keep empty to use the default path, i.e. "
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
vimRcPath.setToolTip(
tr("Keep empty to use the default path, i.e. "
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
vimRcPath.setPlaceHolderText(tr("Default: %1").arg(vimrcDefault));
vimRcPath.setDisplayStyle(FvStringAspect::PathChooserDisplay);
#endif
@ -154,31 +141,22 @@ FakeVimSettings::FakeVimSettings()
FakeVimSettings::~FakeVimSettings() = default;
FvBaseAspect *FakeVimSettings::item(const QString &name)
{
FvBaseAspect *FakeVimSettings::item(const QString &name) {
return m_nameToAspect.value(name, nullptr);
}
QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
{
QString FakeVimSettings::trySetValue(const QString &name, const QString &value) {
FvBaseAspect *aspect = m_nameToAspect.value(name, nullptr);
if (!aspect)
return tr("Unknown option: %1").arg(name);
if (!aspect) return tr("Unknown option: %1").arg(name);
if (aspect == &tabStop || aspect == &shiftWidth) {
if (value.toInt() <= 0)
return tr("Argument must be positive: %1=%2")
.arg(name).arg(value);
if (value.toInt() <= 0) return tr("Argument must be positive: %1=%2").arg(name).arg(value);
}
aspect->setValue(value);
return QString();
}
void FakeVimSettings::setup(FvBaseAspect *aspect,
const QVariant &value,
const QString &settingsKey,
const QString &shortName,
const QString &labelText)
{
void FakeVimSettings::setup(FvBaseAspect *aspect, const QVariant &value, const QString &settingsKey,
const QString &shortName, const QString &labelText) {
aspect->setSettingsKey("FakeVim", settingsKey);
aspect->setDefaultValue(value);
#ifndef FAKEVIM_STANDALONE
@ -197,15 +175,13 @@ void FakeVimSettings::setup(FvBaseAspect *aspect,
m_nameToAspect[longName] = aspect;
m_aspectToName[aspect] = longName;
}
if (!shortName.isEmpty())
m_nameToAspect[shortName] = aspect;
if (!shortName.isEmpty()) m_nameToAspect[shortName] = aspect;
}
FakeVimSettings *fakeVimSettings()
{
FakeVimSettings *fakeVimSettings() {
static FakeVimSettings s;
return &s;
}
} // namespace Internal
} // namespace FakeVim
} // namespace Internal
} // namespace FakeVim

View file

@ -28,9 +28,9 @@
#define FAKEVIM_STANDALONE
#ifdef FAKEVIM_STANDALONE
//# include "private/fakevim_export.h"
// # include "private/fakevim_export.h"
#else
# include <utils/savedaction.h>
#include <utils/savedaction.h>
#endif
#include <QCoreApplication>
@ -43,9 +43,8 @@ namespace FakeVim {
namespace Internal {
#ifdef FAKEVIM_STANDALONE
class FvBaseAspect
{
public:
class FvBaseAspect {
public:
FvBaseAspect();
virtual ~FvBaseAspect() {}
@ -59,34 +58,30 @@ public:
void setDisplayName(const QString &) {}
void setToolTip(const QString &) {}
private:
private:
QVariant m_value;
QVariant m_defaultValue;
QString m_settingsGroup;
QString m_settingsKey;
};
class FvBoolAspect : public FvBaseAspect
{
public:
class FvBoolAspect : public FvBaseAspect {
public:
bool value() const { return FvBaseAspect::value().toBool(); }
};
class FvIntegerAspect : public FvBaseAspect
{
public:
class FvIntegerAspect : public FvBaseAspect {
public:
qint64 value() const { return FvBaseAspect::value().toLongLong(); }
};
class FvStringAspect : public FvBaseAspect
{
public:
class FvStringAspect : public FvBaseAspect {
public:
QString value() const { return FvBaseAspect::value().toString(); }
};
class FvAspectContainer : public FvBaseAspect
{
public:
class FvAspectContainer : public FvBaseAspect {
public:
};
#else
@ -99,11 +94,10 @@ using FvStringAspect = Utils::StringAspect;
#endif
class FakeVimSettings final : public FvAspectContainer
{
class FakeVimSettings final : public FvAspectContainer {
Q_DECLARE_TR_FUNCTIONS(FakeVim)
public:
public:
FakeVimSettings();
~FakeVimSettings();
@ -160,11 +154,9 @@ public:
FvBoolAspect blinkingCursor;
private:
void setup(FvBaseAspect *aspect, const QVariant &value,
const QString &settingsKey,
const QString &shortName,
const QString &label);
private:
void setup(FvBaseAspect *aspect, const QVariant &value, const QString &settingsKey,
const QString &shortName, const QString &label);
QHash<QString, FvBaseAspect *> m_nameToAspect;
QHash<FvBaseAspect *, QString> m_aspectToName;
@ -172,5 +164,5 @@ private:
FakeVimSettings *fakeVimSettings();
} // namespace Internal
} // namespace FakeVim
} // namespace Internal
} // namespace FakeVim

File diff suppressed because it is too large Load diff

View file

@ -28,31 +28,28 @@
#define FAKEVIM_STANDALONE
#ifdef FAKEVIM_STANDALONE
//# include "private/fakevim_export.h"
// # include "private/fakevim_export.h"
#endif
#include <QObject>
#include <QTextEdit>
#include <functional>
#include <vector>
namespace FakeVim {
namespace Internal {
enum RangeMode
{
enum RangeMode {
// Reordering first three enum items here will break
// compatibility with clipboard format stored by Vim.
RangeCharMode, // v
RangeLineMode, // V
RangeBlockMode, // Ctrl-v
RangeCharMode, // v
RangeLineMode, // V
RangeBlockMode, // Ctrl-v
RangeLineModeExclusive,
RangeBlockAndTailMode // Ctrl-v for D and X
RangeBlockAndTailMode // Ctrl-v for D and X
};
struct Range
{
struct Range {
Range() = default;
Range(int b, int e, RangeMode m = RangeCharMode);
QString toString() const;
@ -63,11 +60,9 @@ struct Range
RangeMode rangemode = RangeCharMode;
};
struct ExCommand
{
struct ExCommand {
ExCommand() = default;
ExCommand(const QString &cmd, const QString &args = QString(),
const Range &range = Range());
ExCommand(const QString &cmd, const QString &args = QString(), const Range &range = Range());
bool matches(const QString &min, const QString &full) const;
@ -79,40 +74,35 @@ struct ExCommand
};
// message levels sorted by severity
enum MessageLevel
{
MessageMode, // show current mode (format "-- %1 --")
MessageCommand, // show last Ex command or search
MessageInfo, // result of a command
MessageWarning, // warning
MessageError, // error
MessageShowCmd // partial command
enum MessageLevel {
MessageMode, // show current mode (format "-- %1 --")
MessageCommand, // show last Ex command or search
MessageInfo, // result of a command
MessageWarning, // warning
MessageError, // error
MessageShowCmd // partial command
};
template <typename Type>
class Signal
{
public:
class Signal {
public:
using Callable = std::function<Type>;
void connect(const Callable &callable) { m_callables.push_back(callable); }
template <typename ...Args>
void operator()(Args ...args) const
{
for (const Callable &callable : m_callables)
callable(args...);
}
template <typename... Args>
void operator()(Args... args) const {
for (const Callable &callable : m_callables) callable(args...);
}
private:
private:
std::vector<Callable> m_callables;
};
class FakeVimHandler : public QObject
{
class FakeVimHandler : public QObject {
Q_OBJECT
public:
public:
explicit FakeVimHandler(QWidget *widget, QObject *parent = nullptr);
~FakeVimHandler() override;
@ -123,7 +113,7 @@ public:
static void updateGlobalMarksFilenames(const QString &oldFileName, const QString &newFileName);
public:
public:
void setCurrentFileName(const QString &fileName);
QString currentFileName() const;
@ -159,11 +149,12 @@ public:
bool eventFilter(QObject *ob, QEvent *ev) override;
Signal<void(const QString &msg, int cursorPos, int anchorPos, int messageLevel)> commandBufferChanged;
Signal<void(const QString &msg, int cursorPos, int anchorPos, int messageLevel)>
commandBufferChanged;
Signal<void(const QString &msg)> statusDataChanged;
Signal<void(const QString &msg)> extraInformationChanged;
Signal<void(const QList<QTextEdit::ExtraSelection> &selection)> selectionChanged;
Signal<void(const QString &needle)> highlightMatches;
Signal<void(const QString &needle)> highlightMatches;
Signal<void(bool *moved, bool *forward, QTextCursor *cursor)> moveToMatchingParenthesis;
Signal<void(bool *result, QChar c)> checkForElectricCharacter;
Signal<void(int beginLine, int endLine, QChar typedChar)> indentRegion;
@ -186,14 +177,14 @@ public:
Signal<void()> tabPreviousRequested;
Signal<void()> tabNextRequested;
public:
public:
class Private;
private:
private:
Private *d;
};
} // namespace Internal
} // namespace FakeVim
} // namespace Internal
} // namespace FakeVim
Q_DECLARE_METATYPE(FakeVim::Internal::ExCommand)

View file

@ -29,9 +29,8 @@
namespace FakeVim {
struct Tr
{
struct Tr {
Q_DECLARE_TR_FUNCTIONS(FakeVim)
};
} // namespace FakeVim
} // namespace FakeVim

View file

@ -32,13 +32,11 @@ using namespace Utils;
Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive;
bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false;
void HostOsInfo::setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity)
{
void HostOsInfo::setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity) {
m_useOverrideFileNameCaseSensitivity = true;
m_overrideFileNameCaseSensitivity = sensitivity;
}
void HostOsInfo::unsetOverrideFileNameCaseSensitivity()
{
void HostOsInfo::unsetOverrideFileNameCaseSensitivity() {
m_useOverrideFileNameCaseSensitivity = false;
}

View file

@ -25,23 +25,21 @@
#pragma once
#include "osspecificaspects.h"
#include <QString>
#include "osspecificaspects.h"
#ifdef Q_OS_WIN
#define QTC_HOST_EXE_SUFFIX QTC_WIN_EXE_SUFFIX
#else
#define QTC_HOST_EXE_SUFFIX ""
#endif // Q_OS_WIN
#endif // Q_OS_WIN
namespace Utils {
class HostOsInfo
{
public:
static constexpr OsType hostOs()
{
class HostOsInfo {
public:
static constexpr OsType hostOs() {
#if defined(Q_OS_WIN)
return OsTypeWindows;
#elif defined(Q_OS_LINUX)
@ -58,8 +56,7 @@ public:
static constexpr bool isWindowsHost() { return hostOs() == OsTypeWindows; }
static constexpr bool isLinuxHost() { return hostOs() == OsTypeLinux; }
static constexpr bool isMacHost() { return hostOs() == OsTypeMac; }
static constexpr bool isAnyUnixHost()
{
static constexpr bool isAnyUnixHost() {
#ifdef Q_OS_UNIX
return true;
#else
@ -67,34 +64,28 @@ public:
#endif
}
static QString withExecutableSuffix(const QString &executable)
{
static QString withExecutableSuffix(const QString &executable) {
return OsSpecificAspects::withExecutableSuffix(hostOs(), executable);
}
static void setOverrideFileNameCaseSensitivity(Qt::CaseSensitivity sensitivity);
static void unsetOverrideFileNameCaseSensitivity();
static Qt::CaseSensitivity fileNameCaseSensitivity()
{
static Qt::CaseSensitivity fileNameCaseSensitivity() {
return m_useOverrideFileNameCaseSensitivity
? m_overrideFileNameCaseSensitivity
: OsSpecificAspects::fileNameCaseSensitivity(hostOs());
? m_overrideFileNameCaseSensitivity
: OsSpecificAspects::fileNameCaseSensitivity(hostOs());
}
static QChar pathListSeparator()
{
return OsSpecificAspects::pathListSeparator(hostOs());
}
static QChar pathListSeparator() { return OsSpecificAspects::pathListSeparator(hostOs()); }
static Qt::KeyboardModifier controlModifier()
{
static Qt::KeyboardModifier controlModifier() {
return OsSpecificAspects::controlModifier(hostOs());
}
private:
private:
static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity;
static bool m_useOverrideFileNameCaseSensitivity;
};
} // namespace Utils
} // namespace Utils

View file

@ -83,17 +83,15 @@ using std::experimental::in_place;
// TODO: make_optional is a copy, since there is no sensible way to import functions in C++
template <class T>
constexpr optional<typename std::decay<T>::type> make_optional(T&& v)
{
return optional<typename std::decay<T>::type>(std::experimental::constexpr_forward<T>(v));
constexpr optional<typename std::decay<T>::type> make_optional(T&& v) {
return optional<typename std::decay<T>::type>(std::experimental::constexpr_forward<T>(v));
}
template <class X>
constexpr optional<X&> make_optional(std::reference_wrapper<X> v)
{
return optional<X&>(v.get());
constexpr optional<X&> make_optional(std::reference_wrapper<X> v) {
return optional<X&>(v.get());
}
} // Utils
} // namespace Utils
//#endif
// #endif

View file

@ -36,33 +36,27 @@ enum OsType { OsTypeWindows, OsTypeLinux, OsTypeMac, OsTypeOtherUnix, OsTypeOthe
namespace OsSpecificAspects {
inline QString withExecutableSuffix(OsType osType, const QString &executable)
{
inline QString withExecutableSuffix(OsType osType, const QString &executable) {
QString finalName = executable;
if (osType == OsTypeWindows)
finalName += QLatin1String(QTC_WIN_EXE_SUFFIX);
if (osType == OsTypeWindows) finalName += QLatin1String(QTC_WIN_EXE_SUFFIX);
return finalName;
}
inline Qt::CaseSensitivity fileNameCaseSensitivity(OsType osType)
{
inline Qt::CaseSensitivity fileNameCaseSensitivity(OsType osType) {
return osType == OsTypeWindows || osType == OsTypeMac ? Qt::CaseInsensitive : Qt::CaseSensitive;
}
inline Qt::CaseSensitivity envVarCaseSensitivity(OsType osType)
{
inline Qt::CaseSensitivity envVarCaseSensitivity(OsType osType) {
return fileNameCaseSensitivity(osType);
}
inline QChar pathListSeparator(OsType osType)
{
inline QChar pathListSeparator(OsType osType) {
return QLatin1Char(osType == OsTypeWindows ? ';' : ':');
}
inline Qt::KeyboardModifier controlModifier(OsType osType)
{
inline Qt::KeyboardModifier controlModifier(OsType osType) {
return osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier;
}
} // namespace OsSpecificAspects
} // namespace Utils
} // namespace OsSpecificAspects
} // namespace Utils

View file

@ -29,8 +29,7 @@
namespace Utils {
void writeAssertLocation(const char *msg)
{
void writeAssertLocation(const char *msg) {
static bool goBoom = qEnvironmentVariableIsSet("QTC_FATAL_ASSERTS");
if (goBoom)
qFatal("SOFT ASSERT made fatal: %s", msg);
@ -38,4 +37,4 @@ void writeAssertLocation(const char *msg)
qDebug("SOFT ASSERT: %s", msg);
}
} // namespace Utils
} // namespace Utils

View file

@ -25,16 +25,32 @@
#pragma once
namespace Utils { void writeAssertLocation(const char *msg); }
namespace Utils {
void writeAssertLocation(const char *msg);
}
#define QTC_ASSERT_STRINGIFY_HELPER(x) #x
#define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_HELPER(x)
#define QTC_ASSERT_STRING(cond) ::Utils::writeAssertLocation(\
"\"" cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__))
#define QTC_ASSERT_STRING(cond) \
::Utils::writeAssertLocation("\"" cond "\" in file " __FILE__ \
", line " QTC_ASSERT_STRINGIFY(__LINE__))
// The 'do {...} while (0)' idiom is not used for the main block here to be
// able to use 'break' and 'continue' as 'actions'.
#define QTC_ASSERT(cond, action) if (Q_LIKELY(cond)) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0)
#define QTC_CHECK(cond) if (Q_LIKELY(cond)) {} else { QTC_ASSERT_STRING(#cond); } do {} while (0)
#define QTC_ASSERT(cond, action) \
if (Q_LIKELY(cond)) { \
} else { \
QTC_ASSERT_STRING(#cond); \
action; \
} \
do { \
} while (0)
#define QTC_CHECK(cond) \
if (Q_LIKELY(cond)) { \
} else { \
QTC_ASSERT_STRING(#cond); \
} \
do { \
} while (0)
#define QTC_GUARD(cond) ((Q_LIKELY(cond)) ? true : (QTC_ASSERT_STRING(#cond), false))

View file

@ -2,14 +2,14 @@
#include <string>
class SomeClass {
public:
public:
SomeClass(const std::string &var) : m_var(var) {}
private:
private:
std::string m_var;
};
int main(int argc, const char *argv[])
{
int main(int argc, const char *argv[]) {
using namespace std;
cout << "TESTING...";
cout << "1";

View file

@ -21,10 +21,7 @@ using String = QString;
* Custom toLower function which is much faster than
* c.toLower() directly
*/
static inline QChar toLower(QChar c)
{
return c.isLower() ? c : c.toLower();
}
static inline QChar toLower(QChar c) { return c.isLower() ? c : c.toLower(); }
// internal
// clang-format off
@ -191,8 +188,8 @@ static bool match_recursive(String::const_iterator pattern,
}
// clang-format on
static bool match_internal(StringType pattern, StringType str, int &outScore, unsigned char *matches)
{
static bool match_internal(StringType pattern, StringType str, int &outScore,
unsigned char *matches) {
if (pattern.isEmpty()) {
return true;
}
@ -204,14 +201,13 @@ static bool match_internal(StringType pattern, StringType str, int &outScore, un
const auto patternEnd = pattern.cend();
const auto strEnd = str.cend();
return match_recursive(patternIt, strIt, outScore, strIt, strEnd, patternEnd,
nullptr, matches, 0, recursionCount);
return match_recursive(patternIt, strIt, outScore, strIt, strEnd, patternEnd, nullptr, matches,
0, recursionCount);
}
/**************************************************************/
bool KFuzzyMatcher::matchSimple(StringType pattern, StringType str)
{
bool KFuzzyMatcher::matchSimple(StringType pattern, StringType str) {
auto patternIt = pattern.cbegin();
for (auto strIt = str.cbegin(); strIt != str.cend() && patternIt != pattern.cend(); ++strIt) {
if (strIt->toLower() == patternIt->toLower()) {
@ -221,8 +217,7 @@ bool KFuzzyMatcher::matchSimple(StringType pattern, StringType str)
return patternIt == pattern.cend();
}
KFuzzyMatcher::Result KFuzzyMatcher::match(StringType pattern, StringType str)
{
KFuzzyMatcher::Result KFuzzyMatcher::match(StringType pattern, StringType str) {
uint8_t matches[256];
int score = 0;
const bool matched = match_internal(pattern, str, score, matches);
@ -232,12 +227,9 @@ KFuzzyMatcher::Result KFuzzyMatcher::match(StringType pattern, StringType str)
return result;
}
QString KFuzzyMatcher::toFuzzyMatchedDisplayString(const QString &pattern,
const QString &str,
QString KFuzzyMatcher::toFuzzyMatchedDisplayString(const QString &pattern, const QString &str,
const QString &htmlTag,
const QString &htmlTagClose)
{
const QString &htmlTagClose) {
if (pattern.isEmpty()) {
return str;
}
@ -254,7 +246,7 @@ QString KFuzzyMatcher::toFuzzyMatchedDisplayString(const QString &pattern,
QString string = str;
int offset = 0;
for (int i = 0; i < 256; ++i) {
if (matches[i] == 255){
if (matches[i] == 255) {
break;
}
string.insert(matches[i] + offset, htmlTag);
@ -263,5 +255,4 @@ QString KFuzzyMatcher::toFuzzyMatchedDisplayString(const QString &pattern,
offset += htmlTagClose.size();
}
return string;
}

View file

@ -74,14 +74,12 @@ using StringType = const QString&;
* @short Namespace for fuzzy matching of strings
* @author Waqar Ahmed <waqar.17a@gmail.com>
*/
namespace KFuzzyMatcher
{
namespace KFuzzyMatcher {
/**
* @brief The result of a fuzzy match
*/
struct Result
{
struct Result {
/** Score of this match. This can be negative. if matched is @c false
then the score will be zero.
*/
@ -126,9 +124,7 @@ bool matchSimple(StringType pattern, StringType str);
*/
Result match(StringType pattern, StringType str);
QString toFuzzyMatchedDisplayString(const QString& pattern,
const QString& str,
const QString& htmlTag,
const QString& htmlTagClose);
QString toFuzzyMatchedDisplayString(const QString& pattern, const QString& str,
const QString& htmlTag, const QString& htmlTagClose);
} // namespace KFuzzyMatcher
} // namespace KFuzzyMatcher

View file

@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.7)
project(qlitehtml VERSION 1.0 LANGUAGES CXX)
project(
qlitehtml
VERSION 1.0
LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
@ -13,23 +16,29 @@ set(QLITEHTML_DEVEL_COMPONENT Devel)
set(QLITEHTML_DEVEL_EXCLUDE_FROM_ALL NO)
if(UNIX OR MINGW)
include(GNUInstallDirs)
set(QLITEHTML_BIN_PATH ${CMAKE_INSTALL_BINDIR})
set(QLITEHTML_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR})
set(QLITEHTML_HEADER_PATH ${CMAKE_INSTALL_INCLUDEDIR}/qlitehtml)
include(GNUInstallDirs)
set(QLITEHTML_BIN_PATH ${CMAKE_INSTALL_BINDIR})
set(QLITEHTML_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR})
set(QLITEHTML_HEADER_PATH ${CMAKE_INSTALL_INCLUDEDIR}/qlitehtml)
else()
set(QLITEHTML_BIN_PATH bin)
set(QLITEHTML_LIBRARY_PATH lib)
set(QLITEHTML_HEADER_PATH include/qlitehtml)
set(QLITEHTML_BIN_PATH bin)
set(QLITEHTML_LIBRARY_PATH lib)
set(QLITEHTML_HEADER_PATH include/qlitehtml)
endif()
find_package(QT 5.11 NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(
QT 5.11 NAMES Qt6 Qt5
COMPONENTS Widgets
REQUIRED)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Widgets
REQUIRED)
set(Qt Qt${QT_VERSION_MAJOR})
set(QLITEHTML_BUILD_TESTS OFF)
if (QLITEHTML_BUILD_TESTS)
add_subdirectory(tests/manual/browser)
if(QLITEHTML_BUILD_TESTS)
add_subdirectory(tests/manual/browser)
endif()
add_subdirectory(src)

View file

@ -4,13 +4,13 @@ project(litehtml LANGUAGES C CXX)
include(CTest)
enable_testing()
# Soname
# MAJOR is incremented when symbols are removed or changed in an incompatible way
# MINOR is incremented when new symbols are added
# Soname MAJOR is incremented when symbols are removed or changed in an
# incompatible way MINOR is incremented when new symbols are added
set(PROJECT_MAJOR 0)
set(PROJECT_MINOR 0)
option(EXTERNAL_GUMBO "Link against external gumbo instead of shipping a bundled copy" OFF)
option(EXTERNAL_GUMBO
"Link against external gumbo instead of shipping a bundled copy" OFF)
if(WIN32)
option(EXTERNAL_XXD "Use external xxd" OFF)
else()
@ -18,7 +18,7 @@ else()
endif()
if(NOT EXTERNAL_GUMBO)
add_subdirectory(src/gumbo)
add_subdirectory(src/gumbo)
endif()
set(SOURCE_LITEHTML
@ -64,8 +64,7 @@ set(SOURCE_LITEHTML
src/utf8_strings.cpp
src/web_color.cpp
src/num_cvt.cpp
src/strtod.cpp
)
src/strtod.cpp)
set(HEADER_LITEHTML
include/litehtml.h
@ -116,8 +115,7 @@ set(HEADER_LITEHTML
include/litehtml/url_path.h
include/litehtml/utf8_strings.h
include/litehtml/web_color.h
include/litehtml/num_cvt.h
)
include/litehtml/num_cvt.h)
set(TEST_LITEHTML
containers/test/container_test.cpp
@ -130,30 +128,32 @@ set(TEST_LITEHTML
test/tstring_view_test.cpp
test/url_test.cpp
test/url_path_test.cpp
test/webColorTest.cpp
)
test/webColorTest.cpp)
set(PROJECT_LIB_VERSION ${PROJECT_MAJOR}.${PROJECT_MINOR}.0)
set(PROJECT_SO_VERSION ${PROJECT_MAJOR})
add_library(${PROJECT_NAME} ${SOURCE_LITEHTML})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_LIB_VERSION} SOVERSION ${PROJECT_SO_VERSION})
set_target_properties(
${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_LIB_VERSION}
SOVERSION ${PROJECT_SO_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
C_STANDARD 99
PUBLIC_HEADER "${HEADER_LITEHTML}"
)
set_target_properties(
${PROJECT_NAME}
PROPERTIES CXX_STANDARD 11
C_STANDARD 99
PUBLIC_HEADER "${HEADER_LITEHTML}")
# Export litehtml includes.
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
target_include_directories(
${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
target_include_directories(${PROJECT_NAME} PRIVATE include/${PROJECT_NAME})
option(LITEHTML_UTF8 "Build litehtml with UTF-8 text conversion functions." OFF)
if (LITEHTML_UTF8)
if(LITEHTML_UTF8)
target_compile_definitions(${PROJECT_NAME} PUBLIC LITEHTML_UTF8)
endif()
@ -161,96 +161,94 @@ endif()
target_link_libraries(${PROJECT_NAME} PUBLIC gumbo)
# install and export
install(TARGETS ${PROJECT_NAME}
EXPORT litehtmlTargets
RUNTIME DESTINATION bin COMPONENT libraries
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT libraries
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT libraries
PUBLIC_HEADER DESTINATION include/litehtml
)
install(FILES cmake/litehtmlConfig.cmake DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
install(EXPORT litehtmlTargets FILE litehtmlTargets.cmake DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
install(
TARGETS ${PROJECT_NAME}
EXPORT litehtmlTargets
RUNTIME DESTINATION bin COMPONENT libraries
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT libraries
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT libraries
PUBLIC_HEADER DESTINATION include/litehtml)
install(FILES cmake/litehtmlConfig.cmake
DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
install(
EXPORT litehtmlTargets
FILE litehtmlTargets.cmake
DESTINATION lib${LIB_SUFFIX}/cmake/litehtml)
# Binary Master.css
if (NOT EXTERNAL_XXD)
add_executable(xxd xxd/xxd.c)
set(XXD_COMMAND $<TARGET_FILE:xxd>)
if(NOT EXTERNAL_XXD)
add_executable(xxd xxd/xxd.c)
set(XXD_COMMAND $<TARGET_FILE:xxd>)
else()
find_program(XXD_COMMAND xxd)
find_program(XXD_COMMAND xxd)
endif()
if(WIN32)
file(TO_NATIVE_PATH ${XXD_COMMAND} XXD_COMMAND)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css MASTER_FILE)
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
COMMAND type ${MASTER_FILE} | "${XXD_COMMAND}" -i > ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
file(TO_NATIVE_PATH ${XXD_COMMAND} XXD_COMMAND)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css
MASTER_FILE)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
COMMAND type ${MASTER_FILE} | "${XXD_COMMAND}" -i >
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
else()
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css | xxd -i > ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/include/master.css | xxd -i >
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
endif()
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
PROPERTIES GENERATED TRUE)
# Tests
set(BUILD_TESTING OFF)
if (BUILD_TESTING)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
if(BUILD_TESTING)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker
# settings
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
enable_testing()
enable_testing()
set(TEST_NAME ${PROJECT_NAME}_tests)
set(TEST_NAME ${PROJECT_NAME}_tests)
add_executable(
${TEST_NAME}
${TEST_LITEHTML}
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc
)
add_executable(${TEST_NAME} ${TEST_LITEHTML}
${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
set_target_properties(${TEST_NAME} PROPERTIES
CXX_STANDARD 11
C_STANDARD 99
PUBLIC_HEADER "${HEADER_LITEHTML}"
)
set_target_properties(
${TEST_NAME}
PROPERTIES CXX_STANDARD 11
C_STANDARD 99
PUBLIC_HEADER "${HEADER_LITEHTML}")
target_include_directories(
${TEST_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers
)
target_include_directories(${TEST_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers)
target_link_libraries(
${TEST_NAME}
${PROJECT_NAME}
gtest_main
)
target_link_libraries(${TEST_NAME} ${PROJECT_NAME} gtest_main)
include(GoogleTest)
gtest_discover_tests(${TEST_NAME})
include(GoogleTest)
gtest_discover_tests(${TEST_NAME})
endif()
# set(TEST_NAME ${PROJECT_NAME}_tests)
# add_executable(${TEST_NAME} ${TEST_LITEHTML} ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
# set_target_properties(${TEST_NAME} PROPERTIES
# CXX_STANDARD 11
# C_STANDARD 99
# PUBLIC_HEADER "${HEADER_LITEHTML}"
# )
# target_include_directories(${TEST_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers)
# target_link_libraries(${TEST_NAME} PRIVATE ${PROJECT_NAME})
# # tests
# add_test(NAME contextTest COMMAND ${TEST_NAME} 1)
# add_test(NAME cssTest COMMAND ${TEST_NAME} 2)
# add_test(NAME documentTest COMMAND ${TEST_NAME} 3)
# add_test(NAME layoutGlobalTest COMMAND ${TEST_NAME} 4)
# add_test(NAME mediaQueryTest COMMAND ${TEST_NAME} 5)
# add_test(NAME webColorTest COMMAND ${TEST_NAME} 6)
# endif()
# set(TEST_NAME ${PROJECT_NAME}_tests) add_executable(${TEST_NAME}
# ${TEST_LITEHTML} ${CMAKE_CURRENT_SOURCE_DIR}/src/master.css.inc)
# set_target_properties(${TEST_NAME} PROPERTIES CXX_STANDARD 11 C_STANDARD 99
# PUBLIC_HEADER "${HEADER_LITEHTML}" ) target_include_directories(${TEST_NAME}
# PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/containers)
# target_link_libraries(${TEST_NAME} PRIVATE ${PROJECT_NAME}) # tests
# add_test(NAME contextTest COMMAND ${TEST_NAME} 1) add_test(NAME cssTest
# COMMAND ${TEST_NAME} 2) add_test(NAME documentTest COMMAND ${TEST_NAME} 3)
# add_test(NAME layoutGlobalTest COMMAND ${TEST_NAME} 4) add_test(NAME
# mediaQueryTest COMMAND ${TEST_NAME} 5) add_test(NAME webColorTest COMMAND
# ${TEST_NAME} 6) endif()

View file

@ -1,110 +1,106 @@
#pragma once
#include <windows.h>
#include <mlang.h>
#include <stdlib.h>
#include <cairo-win32.h>
#include <cairo.h>
#include <dib.h>
#include <litehtml.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <mlang.h>
#include <vector>
#include <cairo.h>
#include <cairo-win32.h>
#include <litehtml.h>
#include <dib.h>
#include <stdlib.h>
#include <tchar.h>
#include <txdib.h>
#include <windows.h>
#include <vector>
#ifdef LITEHTML_UTF8
#define t_make_url make_url_utf8
#define t_make_url make_url_utf8
#else
#define t_make_url make_url
#define t_make_url make_url
#endif
struct cairo_clip_box
{
typedef std::vector<cairo_clip_box> vector;
litehtml::position box;
litehtml::border_radiuses radius;
struct cairo_clip_box {
typedef std::vector<cairo_clip_box> vector;
litehtml::position box;
litehtml::border_radiuses radius;
cairo_clip_box(const litehtml::position& vBox, litehtml::border_radiuses vRad)
{
box = vBox;
radius = vRad;
}
cairo_clip_box(const litehtml::position& vBox, litehtml::border_radiuses vRad) {
box = vBox;
radius = vRad;
}
cairo_clip_box(const cairo_clip_box& val)
{
box = val.box;
radius = val.radius;
}
cairo_clip_box& operator=(const cairo_clip_box& val)
{
box = val.box;
radius = val.radius;
return *this;
}
cairo_clip_box(const cairo_clip_box& val) {
box = val.box;
radius = val.radius;
}
cairo_clip_box& operator=(const cairo_clip_box& val) {
box = val.box;
radius = val.radius;
return *this;
}
};
class cairo_container : public litehtml::document_container
{
public:
typedef std::shared_ptr<CTxDIB> image_ptr;
typedef std::map<std::wstring, image_ptr> images_map;
class cairo_container : public litehtml::document_container {
public:
typedef std::shared_ptr<CTxDIB> image_ptr;
typedef std::map<std::wstring, image_ptr> images_map;
protected:
cairo_surface_t* m_temp_surface;
cairo_t* m_temp_cr;
images_map m_images;
cairo_clip_box::vector m_clips;
IMLangFontLink2* m_font_link;
CRITICAL_SECTION m_img_sync;
public:
cairo_container(void);
virtual ~cairo_container(void);
protected:
cairo_surface_t* m_temp_surface;
cairo_t* m_temp_cr;
images_map m_images;
cairo_clip_box::vector m_clips;
IMLangFontLink2* m_font_link;
CRITICAL_SECTION m_img_sync;
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
virtual void delete_font(litehtml::uint_ptr hFont) override;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
public:
cairo_container(void);
virtual ~cairo_container(void);
virtual int pt_to_px(int pt) const override;
virtual int get_default_font_size() const override;
virtual const litehtml::tchar_t* get_default_font_name() const override;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
virtual void draw_image(litehtml::uint_ptr hdc, const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, const litehtml::position& pos);
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
virtual void delete_font(litehtml::uint_ptr hFont) override;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
virtual void del_clip() override;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
virtual void get_media_features(litehtml::media_features& media) const override;
virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const override;
virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) override;
virtual litehtml::tstring resolve_color(const litehtml::tstring& color) const override;
virtual int pt_to_px(int pt) const override;
virtual int get_default_font_size() const override;
virtual const litehtml::tchar_t* get_default_font_name() const override;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
virtual void draw_image(litehtml::uint_ptr hdc, const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, const litehtml::position& pos);
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
virtual void del_clip() override;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
virtual void get_media_features(litehtml::media_features& media) const override;
virtual void get_language(litehtml::tstring& language, litehtml::tstring& culture) const override;
virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) override;
virtual litehtml::tstring resolve_color(const litehtml::tstring& color) const override;
virtual void make_url( LPCWSTR url, LPCWSTR basepath, std::wstring& out ) = 0;
virtual image_ptr get_image(LPCWSTR url, bool redraw_on_ready) = 0;
void clear_images();
void add_image(std::wstring& url, image_ptr& img);
void remove_image(std::wstring& url);
void make_url_utf8( const char* url, const char* basepath, std::wstring& out );
virtual void make_url(LPCWSTR url, LPCWSTR basepath, std::wstring& out) = 0;
virtual image_ptr get_image(LPCWSTR url, bool redraw_on_ready) = 0;
void clear_images();
void add_image(std::wstring& url, image_ptr& img);
void remove_image(std::wstring& url);
void make_url_utf8(const char* url, const char* basepath, std::wstring& out);
protected:
virtual void draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, double line_width);
virtual void fill_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color);
virtual void rounded_rectangle( cairo_t* cr, const litehtml::position &pos, const litehtml::border_radiuses &radius );
protected:
virtual void draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, double line_width);
virtual void fill_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color);
virtual void rounded_rectangle(cairo_t* cr, const litehtml::position& pos, const litehtml::border_radiuses& radius);
void set_color(cairo_t* cr, litehtml::web_color color) { cairo_set_source_rgba(cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0, color.alpha / 255.0); }
private:
simpledib::dib* get_dib(litehtml::uint_ptr hdc) { return (simpledib::dib*) hdc; }
void apply_clip(cairo_t* cr);
bool add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg);
void set_color(cairo_t* cr, litehtml::web_color color) { cairo_set_source_rgba(cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0, color.alpha / 255.0); }
void draw_txdib(cairo_t* cr, CTxDIB* bmp, int x, int y, int cx, int cy);
void lock_images_cache();
void unlock_images_cache();
private:
simpledib::dib* get_dib(litehtml::uint_ptr hdc) { return (simpledib::dib*)hdc; }
void apply_clip(cairo_t* cr);
bool add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg);
void draw_txdib(cairo_t* cr, CTxDIB* bmp, int x, int y, int cx, int cy);
void lock_images_cache();
void unlock_images_cache();
};

View file

@ -1,379 +1,323 @@
#include "cairo_font.h"
cairo_font::cairo_font(IMLangFontLink2* fl, HFONT hFont, int size )
{
init();
m_font_link = fl;
if(m_font_link)
{
m_font_link->AddRef();
}
m_size = size;
set_font(hFont);
cairo_font::cairo_font(IMLangFontLink2* fl, HFONT hFont, int size) {
init();
m_font_link = fl;
if (m_font_link) {
m_font_link->AddRef();
}
m_size = size;
set_font(hFont);
}
cairo_font::cairo_font(IMLangFontLink2* fl, LPCWSTR facename, int size, int weight, BOOL italic, BOOL strikeout, BOOL underline )
{
init();
m_size = size;
m_font_link = fl;
if(m_font_link)
{
m_font_link->AddRef();
}
cairo_font::cairo_font(IMLangFontLink2* fl, LPCWSTR facename, int size, int weight, BOOL italic, BOOL strikeout, BOOL underline) {
init();
m_size = size;
m_font_link = fl;
if (m_font_link) {
m_font_link->AddRef();
}
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
if(!lstrcmpi(facename, L"monospace"))
{
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Courier New");
} else if(!lstrcmpi(facename, L"serif"))
{
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Times New Roman");
} else if(!lstrcmpi(facename, L"sans-serif"))
{
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Arial");
} else if(!lstrcmpi(facename, L"fantasy"))
{
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Impact");
} else if(!lstrcmpi(facename, L"cursive"))
{
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Comic Sans MS");
} else
{
wcscpy_s(lf.lfFaceName, LF_FACESIZE, facename);
}
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
if (!lstrcmpi(facename, L"monospace")) {
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Courier New");
} else if (!lstrcmpi(facename, L"serif")) {
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Times New Roman");
} else if (!lstrcmpi(facename, L"sans-serif")) {
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Arial");
} else if (!lstrcmpi(facename, L"fantasy")) {
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Impact");
} else if (!lstrcmpi(facename, L"cursive")) {
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Comic Sans MS");
} else {
wcscpy_s(lf.lfFaceName, LF_FACESIZE, facename);
}
lf.lfHeight = -size;
lf.lfWeight = weight;
lf.lfItalic = italic;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfStrikeOut = strikeout;
lf.lfUnderline = underline;
lf.lfHeight = -size;
lf.lfWeight = weight;
lf.lfItalic = italic;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfStrikeOut = strikeout;
lf.lfUnderline = underline;
HFONT fnt = CreateFontIndirect(&lf);
set_font(fnt);
HFONT fnt = CreateFontIndirect(&lf);
set_font(fnt);
}
cairo_font::~cairo_font()
{
if(m_font_face)
{
cairo_font_face_destroy(m_font_face);
}
for(size_t i = 0; i < m_linked_fonts.size(); i++)
{
if(m_linked_fonts[i]->hFont)
{
m_font_link->ReleaseFont(m_linked_fonts[i]->hFont);
}
if(m_linked_fonts[i]->font_face)
{
cairo_font_face_destroy(m_linked_fonts[i]->font_face);
}
}
m_linked_fonts.clear();
if(m_font_link)
{
m_font_link->AddRef();
}
if(m_hFont)
{
DeleteObject(m_hFont);
}
cairo_font::~cairo_font() {
if (m_font_face) {
cairo_font_face_destroy(m_font_face);
}
for (size_t i = 0; i < m_linked_fonts.size(); i++) {
if (m_linked_fonts[i]->hFont) {
m_font_link->ReleaseFont(m_linked_fonts[i]->hFont);
}
if (m_linked_fonts[i]->font_face) {
cairo_font_face_destroy(m_linked_fonts[i]->font_face);
}
}
m_linked_fonts.clear();
if (m_font_link) {
m_font_link->AddRef();
}
if (m_hFont) {
DeleteObject(m_hFont);
}
}
void cairo_font::show_text( cairo_t* cr, int x, int y, const litehtml::tchar_t* str )
{
lock();
text_chunk::vector chunks;
split_text(str, chunks);
cairo_set_font_size(cr, m_size);
cairo_move_to(cr, x, y);
for(size_t i = 0; i < chunks.size(); i++)
{
if(chunks[i]->font)
{
cairo_set_font_face(cr, chunks[i]->font->font_face);
} else
{
cairo_set_font_face(cr, m_font_face);
}
cairo_show_text(cr, chunks[i]->text);
}
unlock();
void cairo_font::show_text(cairo_t* cr, int x, int y, const litehtml::tchar_t* str) {
lock();
text_chunk::vector chunks;
split_text(str, chunks);
cairo_set_font_size(cr, m_size);
cairo_move_to(cr, x, y);
for (size_t i = 0; i < chunks.size(); i++) {
if (chunks[i]->font) {
cairo_set_font_face(cr, chunks[i]->font->font_face);
} else {
cairo_set_font_face(cr, m_font_face);
}
cairo_show_text(cr, chunks[i]->text);
}
unlock();
if(m_bUnderline)
{
int tw = text_width(cr, chunks);
if (m_bUnderline) {
int tw = text_width(cr, chunks);
lock();
cairo_set_line_width(cr, 1);
cairo_move_to(cr, x, y + 1.5);
cairo_line_to(cr, x + tw, y + 1.5);
cairo_stroke(cr);
unlock();
}
if(m_bStrikeOut)
{
int tw = text_width(cr, chunks);
lock();
cairo_set_line_width(cr, 1);
cairo_move_to(cr, x, y + 1.5);
cairo_line_to(cr, x + tw, y + 1.5);
cairo_stroke(cr);
unlock();
}
if (m_bStrikeOut) {
int tw = text_width(cr, chunks);
cairo_font_metrics fm;
get_metrics(cr, &fm);
cairo_font_metrics fm;
get_metrics(cr, &fm);
int ln_y = y - fm.x_height / 2;
int ln_y = y - fm.x_height / 2;
lock();
cairo_set_line_width(cr, 1);
cairo_move_to(cr, x, (double) ln_y - 0.5);
cairo_line_to(cr, x + tw, (double) ln_y - 0.5);
cairo_stroke(cr);
unlock();
}
lock();
cairo_set_line_width(cr, 1);
cairo_move_to(cr, x, (double)ln_y - 0.5);
cairo_line_to(cr, x + tw, (double)ln_y - 0.5);
cairo_stroke(cr);
unlock();
}
free_text_chunks(chunks);
free_text_chunks(chunks);
}
void cairo_font::split_text( const litehtml::tchar_t* src, text_chunk::vector& chunks )
{
wchar_t* str;
void cairo_font::split_text(const litehtml::tchar_t* src, text_chunk::vector& chunks) {
wchar_t* str;
#ifdef LITEHTML_UTF8
str = cairo_font::utf8_to_wchar(src);
wchar_t* str_start = str;
str = cairo_font::utf8_to_wchar(src);
wchar_t* str_start = str;
#else
str = (wchar_t*) src;
str = (wchar_t*)src;
#endif
int cch = lstrlen(str);
int cch = lstrlen(str);
HDC hdc = GetDC(NULL);
SelectObject(hdc, m_hFont);
HRESULT hr = S_OK;
while(cch > 0)
{
DWORD dwActualCodePages;
long cchActual;
if(m_font_link)
{
hr = m_font_link->GetStrCodePages(str, cch, m_font_code_pages, &dwActualCodePages, &cchActual);
} else
{
hr = S_FALSE;
}
HDC hdc = GetDC(NULL);
SelectObject(hdc, m_hFont);
HRESULT hr = S_OK;
while (cch > 0) {
DWORD dwActualCodePages;
long cchActual;
if (m_font_link) {
hr = m_font_link->GetStrCodePages(str, cch, m_font_code_pages, &dwActualCodePages, &cchActual);
} else {
hr = S_FALSE;
}
if(hr != S_OK)
{
break;
}
if (hr != S_OK) {
break;
}
text_chunk* chk = new text_chunk;
text_chunk* chk = new text_chunk;
int sz = WideCharToMultiByte(CP_UTF8, 0, str, cchActual, chk->text, 0, NULL, NULL) + 1;
chk->text = new CHAR[sz];
sz = WideCharToMultiByte(CP_UTF8, 0, str, cchActual, chk->text, sz, NULL, NULL);
chk->text[sz] = 0;
chk->font = NULL;
int sz = WideCharToMultiByte(CP_UTF8, 0, str, cchActual, chk->text, 0, NULL, NULL) + 1;
chk->text = new CHAR[sz];
sz = WideCharToMultiByte(CP_UTF8, 0, str, cchActual, chk->text, sz, NULL, NULL);
chk->text[sz] = 0;
chk->font = NULL;
if(!(dwActualCodePages & m_font_code_pages))
{
for(linked_font::vector::iterator i = m_linked_fonts.begin(); i != m_linked_fonts.end(); i++)
{
if((*i)->code_pages == dwActualCodePages)
{
chk->font = (*i);
break;
}
}
if(!chk->font)
{
linked_font* lkf = new linked_font;
lkf->code_pages = dwActualCodePages;
lkf->hFont = NULL;
m_font_link->MapFont(hdc, dwActualCodePages, 0, &lkf->hFont);
if (lkf->hFont)
{
lkf->font_face = create_font_face(lkf->hFont);
m_linked_fonts.push_back(lkf);
}
else
{
delete lkf;
lkf = NULL;
}
chk->font = lkf;
}
}
if (!(dwActualCodePages & m_font_code_pages)) {
for (linked_font::vector::iterator i = m_linked_fonts.begin(); i != m_linked_fonts.end(); i++) {
if ((*i)->code_pages == dwActualCodePages) {
chk->font = (*i);
break;
}
}
if (!chk->font) {
linked_font* lkf = new linked_font;
lkf->code_pages = dwActualCodePages;
lkf->hFont = NULL;
m_font_link->MapFont(hdc, dwActualCodePages, 0, &lkf->hFont);
if (lkf->hFont) {
lkf->font_face = create_font_face(lkf->hFont);
m_linked_fonts.push_back(lkf);
} else {
delete lkf;
lkf = NULL;
}
chk->font = lkf;
}
}
chunks.push_back(chk);
chunks.push_back(chk);
cch -= cchActual;
str += cchActual;
}
cch -= cchActual;
str += cchActual;
}
if(hr != S_OK)
{
text_chunk* chk = new text_chunk;
if (hr != S_OK) {
text_chunk* chk = new text_chunk;
int sz = WideCharToMultiByte(CP_UTF8, 0, str, -1, chk->text, 0, NULL, NULL) + 1;
chk->text = new CHAR[sz];
sz = WideCharToMultiByte(CP_UTF8, 0, str, -1, chk->text, sz, NULL, NULL);
chk->text[sz] = 0;
chk->font = NULL;
chunks.push_back(chk);
}
int sz = WideCharToMultiByte(CP_UTF8, 0, str, -1, chk->text, 0, NULL, NULL) + 1;
chk->text = new CHAR[sz];
sz = WideCharToMultiByte(CP_UTF8, 0, str, -1, chk->text, sz, NULL, NULL);
chk->text[sz] = 0;
chk->font = NULL;
chunks.push_back(chk);
}
ReleaseDC(NULL, hdc);
ReleaseDC(NULL, hdc);
#ifdef LITEHTML_UTF8
delete str_start;
delete str_start;
#endif
}
void cairo_font::free_text_chunks( text_chunk::vector& chunks )
{
for(size_t i = 0; i < chunks.size(); i++)
{
delete chunks[i];
}
chunks.clear();
void cairo_font::free_text_chunks(text_chunk::vector& chunks) {
for (size_t i = 0; i < chunks.size(); i++) {
delete chunks[i];
}
chunks.clear();
}
cairo_font_face_t* cairo_font::create_font_face( HFONT fnt )
{
LOGFONT lf;
GetObject(fnt, sizeof(LOGFONT), &lf);
return cairo_win32_font_face_create_for_logfontw(&lf);
cairo_font_face_t* cairo_font::create_font_face(HFONT fnt) {
LOGFONT lf;
GetObject(fnt, sizeof(LOGFONT), &lf);
return cairo_win32_font_face_create_for_logfontw(&lf);
}
int cairo_font::text_width( cairo_t* cr, const litehtml::tchar_t* str )
{
text_chunk::vector chunks;
split_text(str, chunks);
int cairo_font::text_width(cairo_t* cr, const litehtml::tchar_t* str) {
text_chunk::vector chunks;
split_text(str, chunks);
int ret = text_width(cr, chunks);
int ret = text_width(cr, chunks);
free_text_chunks(chunks);
free_text_chunks(chunks);
return (int) ret;
return (int)ret;
}
int cairo_font::text_width( cairo_t* cr, text_chunk::vector& chunks )
{
lock();
cairo_set_font_size(cr, m_size);
double ret = 0;
for(size_t i = 0; i < chunks.size(); i++)
{
if(chunks[i]->font)
{
cairo_set_font_face(cr, chunks[i]->font->font_face);
} else
{
cairo_set_font_face(cr, m_font_face);
}
cairo_text_extents_t ext;
cairo_text_extents(cr, chunks[i]->text, &ext);
ret += ext.x_advance;
}
unlock();
int cairo_font::text_width(cairo_t* cr, text_chunk::vector& chunks) {
lock();
cairo_set_font_size(cr, m_size);
double ret = 0;
for (size_t i = 0; i < chunks.size(); i++) {
if (chunks[i]->font) {
cairo_set_font_face(cr, chunks[i]->font->font_face);
} else {
cairo_set_font_face(cr, m_font_face);
}
cairo_text_extents_t ext;
cairo_text_extents(cr, chunks[i]->text, &ext);
ret += ext.x_advance;
}
unlock();
return (int) ret;
return (int)ret;
}
void cairo_font::get_metrics(cairo_t* cr, cairo_font_metrics* fm )
{
lock();
cairo_set_font_face(cr, m_font_face);
cairo_set_font_size(cr, m_size);
cairo_font_extents_t ext;
cairo_font_extents(cr, &ext);
void cairo_font::get_metrics(cairo_t* cr, cairo_font_metrics* fm) {
lock();
cairo_set_font_face(cr, m_font_face);
cairo_set_font_size(cr, m_size);
cairo_font_extents_t ext;
cairo_font_extents(cr, &ext);
cairo_text_extents_t tex;
cairo_text_extents(cr, "x", &tex);
cairo_text_extents_t tex;
cairo_text_extents(cr, "x", &tex);
fm->ascent = (int) ext.ascent;
fm->descent = (int) ext.descent;
fm->height = (int) (ext.ascent + ext.descent);
fm->x_height = (int) tex.height;
unlock();
fm->ascent = (int)ext.ascent;
fm->descent = (int)ext.descent;
fm->height = (int)(ext.ascent + ext.descent);
fm->x_height = (int)tex.height;
unlock();
}
void cairo_font::set_font( HFONT hFont )
{
clear();
void cairo_font::set_font(HFONT hFont) {
clear();
m_hFont = hFont;
m_font_face = create_font_face(m_hFont);
m_font_code_pages = 0;
if(m_font_link)
{
HDC hdc = GetDC(NULL);
SelectObject(hdc, m_hFont);
m_font_link->GetFontCodePages(hdc, m_hFont, &m_font_code_pages);
ReleaseDC(NULL, hdc);
}
LOGFONT lf;
GetObject(m_hFont, sizeof(LOGFONT), &lf);
m_bUnderline = lf.lfUnderline;
m_bStrikeOut = lf.lfStrikeOut;
m_hFont = hFont;
m_font_face = create_font_face(m_hFont);
m_font_code_pages = 0;
if (m_font_link) {
HDC hdc = GetDC(NULL);
SelectObject(hdc, m_hFont);
m_font_link->GetFontCodePages(hdc, m_hFont, &m_font_code_pages);
ReleaseDC(NULL, hdc);
}
LOGFONT lf;
GetObject(m_hFont, sizeof(LOGFONT), &lf);
m_bUnderline = lf.lfUnderline;
m_bStrikeOut = lf.lfStrikeOut;
}
void cairo_font::clear()
{
if(m_font_face)
{
cairo_font_face_destroy(m_font_face);
m_font_face = NULL;
}
for(size_t i = 0; i < m_linked_fonts.size(); i++)
{
if(m_linked_fonts[i]->hFont && m_font_link)
{
m_font_link->ReleaseFont(m_linked_fonts[i]->hFont);
}
if(m_linked_fonts[i]->font_face)
{
cairo_font_face_destroy(m_linked_fonts[i]->font_face);
}
}
m_linked_fonts.clear();
if(m_hFont)
{
DeleteObject(m_hFont);
m_hFont = NULL;
}
void cairo_font::clear() {
if (m_font_face) {
cairo_font_face_destroy(m_font_face);
m_font_face = NULL;
}
for (size_t i = 0; i < m_linked_fonts.size(); i++) {
if (m_linked_fonts[i]->hFont && m_font_link) {
m_font_link->ReleaseFont(m_linked_fonts[i]->hFont);
}
if (m_linked_fonts[i]->font_face) {
cairo_font_face_destroy(m_linked_fonts[i]->font_face);
}
}
m_linked_fonts.clear();
if (m_hFont) {
DeleteObject(m_hFont);
m_hFont = NULL;
}
}
void cairo_font::init()
{
m_hFont = NULL;
m_font_face = NULL;
m_font_link = NULL;
m_font_code_pages = 0;
m_size = 0;
m_bUnderline = FALSE;
m_bStrikeOut = FALSE;
void cairo_font::init() {
m_hFont = NULL;
m_font_face = NULL;
m_font_link = NULL;
m_font_code_pages = 0;
m_size = 0;
m_bUnderline = FALSE;
m_bStrikeOut = FALSE;
}
wchar_t* cairo_font::utf8_to_wchar( const char* src )
{
if(!src) return NULL;
wchar_t* cairo_font::utf8_to_wchar(const char* src) {
if (!src) return NULL;
int len = (int) strlen(src);
wchar_t* ret = new wchar_t[len + 1];
MultiByteToWideChar(CP_UTF8, 0, src, -1, ret, len + 1);
return ret;
int len = (int)strlen(src);
wchar_t* ret = new wchar_t[len + 1];
MultiByteToWideChar(CP_UTF8, 0, src, -1, ret, len + 1);
return ret;
}
char* cairo_font::wchar_to_utf8( const wchar_t* src )
{
if(!src) return NULL;
char* cairo_font::wchar_to_utf8(const wchar_t* src) {
if (!src) return NULL;
int len = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL);
char* ret = new char[len];
WideCharToMultiByte(CP_UTF8, 0, src, -1, ret, len, NULL, NULL);
return ret;
int len = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL);
char* ret = new char[len];
WideCharToMultiByte(CP_UTF8, 0, src, -1, ret, len, NULL, NULL);
return ret;
}

View file

@ -1,117 +1,99 @@
#pragma once
#include <windows.h>
#include <stdlib.h>
#include <cairo-win32.h>
#include <cairo.h>
#include <litehtml.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <mlang.h>
#include <stdlib.h>
#include <tchar.h>
#include <windows.h>
#include <vector>
#include <cairo.h>
#include <cairo-win32.h>
#include <litehtml.h>
struct linked_font
{
typedef std::vector<linked_font*> vector;
struct linked_font {
typedef std::vector<linked_font*> vector;
DWORD code_pages;
HFONT hFont;
cairo_font_face_t* font_face;
DWORD code_pages;
HFONT hFont;
cairo_font_face_t* font_face;
};
struct text_chunk
{
typedef std::vector<text_chunk*> vector;
struct text_chunk {
typedef std::vector<text_chunk*> vector;
char* text;
linked_font* font;
char* text;
linked_font* font;
~text_chunk()
{
if(text)
{
delete text;
}
}
~text_chunk() {
if (text) {
delete text;
}
}
};
struct cairo_font_metrics
{
int height;
int ascent;
int descent;
int x_height;
struct cairo_font_metrics {
int height;
int ascent;
int descent;
int x_height;
};
class cairo_font {
HFONT m_hFont;
cairo_font_face_t* m_font_face;
IMLangFontLink2* m_font_link;
DWORD m_font_code_pages;
linked_font::vector m_linked_fonts;
int m_size;
BOOL m_bUnderline;
BOOL m_bStrikeOut;
cairo_font_metrics m_metrics;
class cairo_font
{
HFONT m_hFont;
cairo_font_face_t* m_font_face;
IMLangFontLink2* m_font_link;
DWORD m_font_code_pages;
linked_font::vector m_linked_fonts;
int m_size;
BOOL m_bUnderline;
BOOL m_bStrikeOut;
cairo_font_metrics m_metrics;
public:
// fonts are not thread safe :(
// you have to declare and initialize cairo_font::m_sync before the first using.
static CRITICAL_SECTION m_sync;
public:
// fonts are not thread safe :(
// you have to declare and initialize cairo_font::m_sync before the first using.
static CRITICAL_SECTION m_sync;
cairo_font(IMLangFontLink2* fl, HFONT hFont, int size);
cairo_font(IMLangFontLink2* fl, LPCWSTR facename, int size, int weight, BOOL italic, BOOL strikeout, BOOL underline);
cairo_font(IMLangFontLink2* fl, HFONT hFont, int size);
cairo_font(IMLangFontLink2* fl, LPCWSTR facename, int size, int weight, BOOL italic, BOOL strikeout, BOOL underline);
void init();
~cairo_font();
void init();
~cairo_font();
void show_text(cairo_t* cr, int x, int y, const litehtml::tchar_t*);
int text_width(cairo_t* cr, const litehtml::tchar_t* str);
void load_metrics(cairo_t* cr);
cairo_font_metrics& metrics();
static wchar_t* utf8_to_wchar(const char* src);
static char* wchar_to_utf8(const wchar_t* src);
private:
void split_text(const litehtml::tchar_t* str, text_chunk::vector& chunks);
void free_text_chunks(text_chunk::vector& chunks);
cairo_font_face_t* create_font_face(HFONT fnt);
void set_font(HFONT hFont);
void clear();
int text_width(cairo_t* cr, text_chunk::vector& chunks);
void lock();
void unlock();
int round_d(double val);
void get_metrics(cairo_t* cr, cairo_font_metrics* fm);
void show_text(cairo_t* cr, int x, int y, const litehtml::tchar_t*);
int text_width(cairo_t* cr, const litehtml::tchar_t* str);
void load_metrics(cairo_t* cr);
cairo_font_metrics& metrics();
static wchar_t* utf8_to_wchar(const char* src);
static char* wchar_to_utf8(const wchar_t* src);
private:
void split_text(const litehtml::tchar_t* str, text_chunk::vector& chunks);
void free_text_chunks(text_chunk::vector& chunks);
cairo_font_face_t* create_font_face(HFONT fnt);
void set_font(HFONT hFont);
void clear();
int text_width(cairo_t* cr, text_chunk::vector& chunks);
void lock();
void unlock();
int round_d(double val);
void get_metrics(cairo_t* cr, cairo_font_metrics* fm);
};
inline void cairo_font::lock()
{
EnterCriticalSection(&m_sync);
inline void cairo_font::lock() { EnterCriticalSection(&m_sync); }
inline void cairo_font::unlock() { LeaveCriticalSection(&m_sync); }
inline int cairo_font::round_d(double val) {
int int_val = (int)val;
if (val - int_val >= 0.5) {
int_val++;
}
return int_val;
}
inline void cairo_font::unlock()
{
LeaveCriticalSection(&m_sync);
}
inline cairo_font_metrics& cairo_font::metrics() { return m_metrics; }
inline int cairo_font::round_d(double val)
{
int int_val = (int) val;
if(val - int_val >= 0.5)
{
int_val++;
}
return int_val;
}
inline cairo_font_metrics& cairo_font::metrics()
{
return m_metrics;
}
inline void cairo_font::load_metrics(cairo_t* cr)
{
get_metrics(cr, &m_metrics);
}
inline void cairo_font::load_metrics(cairo_t* cr) { get_metrics(cr, &m_metrics); }

View file

@ -1,198 +1,159 @@
#include "gdiplus_container.h"
gdiplus_container::gdiplus_container(void)
{
gdiplus_container::gdiplus_container(void) {}
gdiplus_container::~gdiplus_container(void) {}
void gdiplus_container::draw_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, int line_width) {
Gdiplus::Graphics graphics(hdc);
Gdiplus::LinearGradientBrush* brush = NULL;
graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
Gdiplus::Pen pen(Gdiplus::Color(color.alpha, color.red, color.green, color.blue));
graphics.DrawEllipse(&pen, x, y, width, height);
}
gdiplus_container::~gdiplus_container(void)
{
void gdiplus_container::fill_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color) {
Gdiplus::Graphics graphics(hdc);
graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
Gdiplus::SolidBrush brush(Gdiplus::Color(color.alpha, color.red, color.green, color.blue));
graphics.FillEllipse(&brush, x, y, width, height);
}
void gdiplus_container::draw_ellipse( HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, int line_width )
{
Gdiplus::Graphics graphics(hdc);
Gdiplus::LinearGradientBrush* brush = NULL;
void gdiplus_container::fill_rect(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, const litehtml::css_border_radius& radius) {
Gdiplus::Graphics graphics(hdc);
graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
Gdiplus::Pen pen( Gdiplus::Color(color.alpha, color.red, color.green, color.blue) );
graphics.DrawEllipse(&pen, x, y, width, height);
Gdiplus::SolidBrush brush(Gdiplus::Color(color.alpha, color.red, color.green, color.blue));
graphics.FillRectangle(&brush, x, y, width, height);
}
void gdiplus_container::fill_ellipse( HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color )
{
Gdiplus::Graphics graphics(hdc);
graphics.SetCompositingQuality(Gdiplus::CompositingQualityHighQuality);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
Gdiplus::SolidBrush brush( Gdiplus::Color(color.alpha, color.red, color.green, color.blue) );
graphics.FillEllipse(&brush, x, y, width, height);
void gdiplus_container::get_img_size(litehtml::uint_ptr img, litehtml::size& sz) {
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*)img;
if (bmp) {
sz.width = bmp->GetWidth();
sz.height = bmp->GetHeight();
}
}
void gdiplus_container::fill_rect( HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, const litehtml::css_border_radius& radius )
{
Gdiplus::Graphics graphics(hdc);
Gdiplus::SolidBrush brush( Gdiplus::Color(color.alpha, color.red, color.green, color.blue) );
graphics.FillRectangle(&brush, x, y, width, height);
void gdiplus_container::draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos) {
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*)img;
if (bmp) {
Gdiplus::Graphics graphics(hdc);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
graphics.DrawImage(bmp, pos.x, pos.y, pos.width, pos.height);
}
}
void gdiplus_container::get_img_size( litehtml::uint_ptr img, litehtml::size& sz )
{
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*) img;
if(bmp)
{
sz.width = bmp->GetWidth();
sz.height = bmp->GetHeight();
}
void gdiplus_container::free_image(litehtml::uint_ptr img) {
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*)img;
if (bmp) {
delete bmp;
}
}
void gdiplus_container::draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos )
{
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*) img;
if(bmp)
{
Gdiplus::Graphics graphics(hdc);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
graphics.DrawImage(bmp, pos.x, pos.y, pos.width, pos.height);
}
void gdiplus_container::draw_img_bg(HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment) {
Gdiplus::Bitmap* bgbmp = (Gdiplus::Bitmap*)img;
int img_width = bgbmp->GetWidth();
int img_height = bgbmp->GetHeight();
Gdiplus::Graphics graphics(hdc);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
Gdiplus::Region reg(Gdiplus::Rect(draw_pos.left(), draw_pos.top(), draw_pos.width, draw_pos.height));
graphics.SetClip(&reg);
switch (repeat) {
case litehtml::background_repeat_no_repeat: {
graphics.DrawImage(bgbmp, pos.x, pos.y, bgbmp->GetWidth(), bgbmp->GetHeight());
} break;
case litehtml::background_repeat_repeat_x: {
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
for (int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth()) {
graphics.DrawCachedBitmap(&bmp, x, pos.top());
}
for (int x = pos.left() - bgbmp->GetWidth(); x + (int)bgbmp->GetWidth() > draw_pos.left(); x -= bgbmp->GetWidth()) {
graphics.DrawCachedBitmap(&bmp, x, pos.top());
}
} break;
case litehtml::background_repeat_repeat_y: {
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
for (int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight()) {
graphics.DrawCachedBitmap(&bmp, pos.left(), y);
}
for (int y = pos.top() - bgbmp->GetHeight(); y + (int)bgbmp->GetHeight() > draw_pos.top(); y -= bgbmp->GetHeight()) {
graphics.DrawCachedBitmap(&bmp, pos.left(), y);
}
} break;
case litehtml::background_repeat_repeat: {
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
if (bgbmp->GetHeight() >= 0) {
for (int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth()) {
for (int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight()) {
graphics.DrawCachedBitmap(&bmp, x, y);
}
}
}
} break;
}
}
void gdiplus_container::free_image( litehtml::uint_ptr img )
{
Gdiplus::Bitmap* bmp = (Gdiplus::Bitmap*) img;
if(bmp)
{
delete bmp;
}
}
void gdiplus_container::draw_img_bg( HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment )
{
Gdiplus::Bitmap* bgbmp = (Gdiplus::Bitmap*) img;
int img_width = bgbmp->GetWidth();
int img_height = bgbmp->GetHeight();
Gdiplus::Graphics graphics(hdc);
graphics.SetInterpolationMode(Gdiplus::InterpolationModeNearestNeighbor);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
Gdiplus::Region reg(Gdiplus::Rect(draw_pos.left(), draw_pos.top(), draw_pos.width, draw_pos.height));
graphics.SetClip(&reg);
switch(repeat)
{
case litehtml::background_repeat_no_repeat:
{
graphics.DrawImage(bgbmp, pos.x, pos.y, bgbmp->GetWidth(), bgbmp->GetHeight());
}
break;
case litehtml::background_repeat_repeat_x:
{
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
for(int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth())
{
graphics.DrawCachedBitmap(&bmp, x, pos.top());
}
for(int x = pos.left() - bgbmp->GetWidth(); x + (int) bgbmp->GetWidth() > draw_pos.left(); x -= bgbmp->GetWidth())
{
graphics.DrawCachedBitmap(&bmp, x, pos.top());
}
}
break;
case litehtml::background_repeat_repeat_y:
{
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
for(int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight())
{
graphics.DrawCachedBitmap(&bmp, pos.left(), y);
}
for(int y = pos.top() - bgbmp->GetHeight(); y + (int) bgbmp->GetHeight() > draw_pos.top(); y -= bgbmp->GetHeight())
{
graphics.DrawCachedBitmap(&bmp, pos.left(), y);
}
}
break;
case litehtml::background_repeat_repeat:
{
Gdiplus::CachedBitmap bmp(bgbmp, &graphics);
if(bgbmp->GetHeight() >= 0)
{
for(int x = pos.left(); x < pos.right(); x += bgbmp->GetWidth())
{
for(int y = pos.top(); y < pos.bottom(); y += bgbmp->GetHeight())
{
graphics.DrawCachedBitmap(&bmp, x, y);
}
}
}
}
break;
}
}
void gdiplus_container::draw_borders( litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos )
{
apply_clip((HDC) hdc);
// draw left border
if(borders.left.width.val() != 0 && borders.left.style > litehtml::border_style_hidden)
{
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.left.color.red, borders.left.color.green, borders.left.color.blue));
HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen);
for(int x = 0; x < borders.left.width.val(); x++)
{
MoveToEx((HDC) hdc, draw_pos.left() + x, draw_pos.top(), NULL);
LineTo((HDC) hdc, draw_pos.left() + x, draw_pos.bottom());
}
SelectObject((HDC) hdc, oldPen);
DeleteObject(pen);
}
// draw right border
if(borders.right.width.val() != 0 && borders.right.style > litehtml::border_style_hidden)
{
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.right.color.red, borders.right.color.green, borders.right.color.blue));
HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen);
for(int x = 0; x < borders.right.width.val(); x++)
{
MoveToEx((HDC) hdc, draw_pos.right() - x - 1, draw_pos.top(), NULL);
LineTo((HDC) hdc, draw_pos.right() - x - 1, draw_pos.bottom());
}
SelectObject((HDC) hdc, oldPen);
DeleteObject(pen);
}
// draw top border
if(borders.top.width.val() != 0 && borders.top.style > litehtml::border_style_hidden)
{
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.top.color.red, borders.top.color.green, borders.top.color.blue));
HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen);
for(int y = 0; y < borders.top.width.val(); y++)
{
MoveToEx((HDC) hdc, draw_pos.left(), draw_pos.top() + y, NULL);
LineTo((HDC) hdc, draw_pos.right(), draw_pos.top() + y);
}
SelectObject((HDC) hdc, oldPen);
DeleteObject(pen);
}
// draw bottom border
if(borders.bottom.width.val() != 0 && borders.bottom.style > litehtml::border_style_hidden)
{
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.bottom.color.red, borders.bottom.color.green, borders.bottom.color.blue));
HPEN oldPen = (HPEN) SelectObject((HDC) hdc, pen);
for(int y = 0; y < borders.bottom.width.val(); y++)
{
MoveToEx((HDC) hdc, draw_pos.left(), draw_pos.bottom() - y - 1, NULL);
LineTo((HDC) hdc, draw_pos.right(), draw_pos.bottom() - y - 1);
}
SelectObject((HDC) hdc, oldPen);
DeleteObject(pen);
}
release_clip((HDC) hdc);
void gdiplus_container::draw_borders(litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos) {
apply_clip((HDC)hdc);
// draw left border
if (borders.left.width.val() != 0 && borders.left.style > litehtml::border_style_hidden) {
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.left.color.red, borders.left.color.green, borders.left.color.blue));
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
for (int x = 0; x < borders.left.width.val(); x++) {
MoveToEx((HDC)hdc, draw_pos.left() + x, draw_pos.top(), NULL);
LineTo((HDC)hdc, draw_pos.left() + x, draw_pos.bottom());
}
SelectObject((HDC)hdc, oldPen);
DeleteObject(pen);
}
// draw right border
if (borders.right.width.val() != 0 && borders.right.style > litehtml::border_style_hidden) {
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.right.color.red, borders.right.color.green, borders.right.color.blue));
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
for (int x = 0; x < borders.right.width.val(); x++) {
MoveToEx((HDC)hdc, draw_pos.right() - x - 1, draw_pos.top(), NULL);
LineTo((HDC)hdc, draw_pos.right() - x - 1, draw_pos.bottom());
}
SelectObject((HDC)hdc, oldPen);
DeleteObject(pen);
}
// draw top border
if (borders.top.width.val() != 0 && borders.top.style > litehtml::border_style_hidden) {
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.top.color.red, borders.top.color.green, borders.top.color.blue));
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
for (int y = 0; y < borders.top.width.val(); y++) {
MoveToEx((HDC)hdc, draw_pos.left(), draw_pos.top() + y, NULL);
LineTo((HDC)hdc, draw_pos.right(), draw_pos.top() + y);
}
SelectObject((HDC)hdc, oldPen);
DeleteObject(pen);
}
// draw bottom border
if (borders.bottom.width.val() != 0 && borders.bottom.style > litehtml::border_style_hidden) {
HPEN pen = CreatePen(PS_SOLID, 1, RGB(borders.bottom.color.red, borders.bottom.color.green, borders.bottom.color.blue));
HPEN oldPen = (HPEN)SelectObject((HDC)hdc, pen);
for (int y = 0; y < borders.bottom.width.val(); y++) {
MoveToEx((HDC)hdc, draw_pos.left(), draw_pos.bottom() - y - 1, NULL);
LineTo((HDC)hdc, draw_pos.right(), draw_pos.bottom() - y - 1);
}
SelectObject((HDC)hdc, oldPen);
DeleteObject(pen);
}
release_clip((HDC)hdc);
}

View file

@ -1,29 +1,29 @@
#pragma once
#include <windows.h>
#include <mlang.h>
#include <stdlib.h>
#include <GdiPlus.h>
#include <litehtml.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <mlang.h>
#include <stdlib.h>
#include <tchar.h>
#include <windows.h>
#include <vector>
#include <litehtml.h>
#include <GdiPlus.h>
#include "..\win32\win32_container.h"
class gdiplus_container : public litehtml::win32_container
{
public:
gdiplus_container(void);
virtual ~gdiplus_container(void);
class gdiplus_container : public litehtml::win32_container {
public:
gdiplus_container(void);
virtual ~gdiplus_container(void);
protected:
virtual void draw_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
virtual void fill_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color);
virtual void fill_rect(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, const litehtml::css_border_radius& radius);
virtual void get_img_size(litehtml::uint_ptr img, litehtml::size& sz);
virtual void draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos);
virtual void free_image(litehtml::uint_ptr img);
virtual void draw_img_bg(HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment);
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos);
protected:
virtual void draw_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
virtual void fill_ellipse(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color);
virtual void fill_rect(HDC hdc, int x, int y, int width, int height, const litehtml::web_color& color, const litehtml::css_border_radius& radius);
virtual void get_img_size(litehtml::uint_ptr img, litehtml::size& sz);
virtual void draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos);
virtual void free_image(litehtml::uint_ptr img);
virtual void draw_img_bg(HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment);
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::css_borders& borders, const litehtml::position& draw_pos);
};

View file

@ -6,563 +6,425 @@
*/
#include "container_haiku.h"
#include <string>
#include <iostream>
#include <fstream>
#include <streambuf>
#include <map>
#include <Bitmap.h>
#include <String.h>
#include <Entry.h>
#include <Path.h>
#include <String.h>
#include <TranslationUtils.h>
LiteHtmlView::LiteHtmlView(BRect frame, const char *name)
: BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW),
fContext(NULL),
m_html(NULL),
m_images(),
m_base_url(),
m_url()
{
#include <fstream>
#include <iostream>
#include <map>
#include <streambuf>
#include <string>
BRect bounds(Bounds());
BPoint topLeft = bounds.LeftTop();
std::cout << "Initial bounds: topLeft x: " << +topLeft.x << ", y: "
<< +topLeft.y << ", width: " << +bounds.Width() << ", height: "
<< +bounds.Height() << std::endl;
LiteHtmlView::LiteHtmlView(BRect frame, const char* name) : BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW), fContext(NULL), m_html(NULL), m_images(), m_base_url(), m_url() {
BRect bounds(Bounds());
BPoint topLeft = bounds.LeftTop();
std::cout << "Initial bounds: topLeft x: " << +topLeft.x << ", y: " << +topLeft.y << ", width: " << +bounds.Width() << ", height: " << +bounds.Height() << std::endl;
SetDrawingMode(B_OP_OVER);
SetFont(be_plain_font);
SetDrawingMode(B_OP_OVER);
SetFont(be_plain_font);
//FillRect(bounds,B_SOLID_LOW);
// FillRect(bounds,B_SOLID_LOW);
//SetLowColor(B_DOCUMENT_PANEL_COLOR);
//FillRect(rect);
// SetLowColor(B_DOCUMENT_PANEL_COLOR);
// FillRect(rect);
}
LiteHtmlView::~LiteHtmlView()
{
LiteHtmlView::~LiteHtmlView() {}
void LiteHtmlView::SetContext(litehtml::context* ctx) { fContext = ctx; }
void LiteHtmlView::RenderFile(const char* localFilePath) {
std::cout << "RenderFile" << std::endl;
// BUrlRequest req;
// assume a local file for now, that is HTML
std::ifstream t(localFilePath);
std::string html((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
// std::cout << "HTML output:-" << std::endl << html << std::endl;
// Get parent folder for the base url
std::cout << "Loaded from file: " << localFilePath << std::endl;
BPath htmlPath(localFilePath);
BPath dirPath;
htmlPath.GetParent(&dirPath);
std::cout << "parent path: " << dirPath.Path() << std::endl;
set_base_url(dirPath.Path());
// std::cout << " base url now:" << m_base_url << std::endl;
RenderHTML(html);
}
void
LiteHtmlView::SetContext(litehtml::context* ctx)
{
fContext = ctx;
void LiteHtmlView::RenderHTML(const std::string& htmlText) {
std::cout << "RenderHTML" << std::endl;
// now use this string
m_html = litehtml::document::createFromString(htmlText.c_str(), this, fContext);
if (m_html) {
std::cout << "Successfully read html" << std::endl;
// success
// post-parse render operations, if required.
Invalidate();
} else {
std::cout << "Failed to read html" << std::endl;
}
// always fire the rendering complete message
std::cout << "Sending html rendered message: " << M_HTML_RENDERED << std::endl;
}
void
LiteHtmlView::RenderFile(const char* localFilePath)
{
std::cout << "RenderFile" << std::endl;
//BUrlRequest req;
// assume a local file for now, that is HTML
std::ifstream t(localFilePath);
std::string html((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
void LiteHtmlView::Draw(BRect b) {
std::cout << "DRAW CALLED" << std::endl;
//std::cout << "HTML output:-" << std::endl << html << std::endl;
BRect bounds(Bounds());
FillRect(bounds, B_SOLID_LOW);
// Get parent folder for the base url
std::cout << "Loaded from file: " << localFilePath << std::endl;
BPath htmlPath(localFilePath);
BPath dirPath;
htmlPath.GetParent(&dirPath);
std::cout << "parent path: " << dirPath.Path() << std::endl;
set_base_url(dirPath.Path());
//std::cout << " base url now:" << m_base_url << std::endl;
// b only part of the window, but we need to draw the whole lot
RenderHTML(html);
if (NULL != m_html) {
BPoint leftTop = bounds.LeftTop();
litehtml::position clip(leftTop.x, leftTop.y, bounds.Width(), bounds.Height());
m_html->render(bounds.Width());
m_html->draw((litehtml::uint_ptr)this, 0, 0, &clip);
}
SendNotices(M_HTML_RENDERED, new BMessage(M_HTML_RENDERED));
}
void
LiteHtmlView::RenderHTML(const std::string& htmlText)
{
std::cout << "RenderHTML" << std::endl;
// now use this string
m_html = litehtml::document::createFromString(
htmlText.c_str(), this, fContext);
if (m_html)
{
std::cout << "Successfully read html" << std::endl;
// success
// post-parse render operations, if required.
Invalidate();
} else {
std::cout << "Failed to read html" << std::endl;
}
// always fire the rendering complete message
std::cout << "Sending html rendered message: " << M_HTML_RENDERED << std::endl;
void LiteHtmlView::GetPreferredSize(float* width, float* height) {
if (NULL == m_html) {
BRect bounds(Bounds());
*width = bounds.Width();
*height = bounds.Height();
} else {
*width = m_html->width();
*height = m_html->height();
}
}
void
LiteHtmlView::Draw(BRect b)
{
std::cout << "DRAW CALLED" << std::endl;
litehtml::uint_ptr LiteHtmlView::create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) {
// std::cout << "create_font" << std::endl;
litehtml::string_vector fonts;
litehtml::split_string(faceName, fonts, ",");
litehtml::trim(fonts[0]);
BRect bounds(Bounds());
FillRect(bounds,B_SOLID_LOW);
// b only part of the window, but we need to draw the whole lot
if (NULL != m_html) {
BPoint leftTop = bounds.LeftTop();
litehtml::position clip(leftTop.x,leftTop.y,
bounds.Width(),bounds.Height());
m_html->render(bounds.Width());
m_html->draw((litehtml::uint_ptr) this,0,0,&clip);
}
SendNotices(M_HTML_RENDERED,new BMessage(M_HTML_RENDERED));
}
void
LiteHtmlView::GetPreferredSize(float* width,float* height)
{
if (NULL == m_html)
{
BRect bounds(Bounds());
*width = bounds.Width();
*height = bounds.Height();
} else {
*width = m_html->width();
*height = m_html->height();
}
}
litehtml::uint_ptr
LiteHtmlView::create_font( const litehtml::tchar_t* faceName, int size,
int weight, litehtml::font_style italic, unsigned int decoration,
litehtml::font_metrics* fm )
{
//std::cout << "create_font" << std::endl;
litehtml::string_vector fonts;
litehtml::split_string(faceName, fonts, ",");
litehtml::trim(fonts[0]);
uint16 face = B_REGULAR_FACE; // default
if (italic == litehtml::fontStyleItalic)
{
face |= B_ITALIC_FACE;
}
if (decoration & litehtml::font_decoration_underline)
{
face |= B_UNDERSCORE_FACE;
}
if (decoration & litehtml::font_decoration_linethrough)
{
face |= B_STRIKEOUT_FACE;
}
// Note: LIGHT, HEAVY, CONDENSED not supported in BeOS R5
uint16 face = B_REGULAR_FACE; // default
if (italic == litehtml::fontStyleItalic) {
face |= B_ITALIC_FACE;
}
if (decoration & litehtml::font_decoration_underline) {
face |= B_UNDERSCORE_FACE;
}
if (decoration & litehtml::font_decoration_linethrough) {
face |= B_STRIKEOUT_FACE;
}
// Note: LIGHT, HEAVY, CONDENSED not supported in BeOS R5
#ifdef __HAIKU__
if(weight >= 0 && weight < 150) face |= B_LIGHT_FACE;
else if(weight >= 150 && weight < 250) face |= B_LIGHT_FACE;
else if(weight >= 250 && weight < 350) face |= B_LIGHT_FACE;
//else if(weight >= 350 && weight < 450) face |= B_REGULAR_FACE;
//else if(weight >= 450 && weight < 550) face |= B_REGULAR_FACE;
else if(weight >= 550 && weight < 650) face |= B_CONDENSED_FACE;
if (weight >= 0 && weight < 150)
face |= B_LIGHT_FACE;
else if (weight >= 150 && weight < 250)
face |= B_LIGHT_FACE;
else if (weight >= 250 && weight < 350)
face |= B_LIGHT_FACE;
// else if(weight >= 350 && weight < 450) face |= B_REGULAR_FACE;
// else if(weight >= 450 && weight < 550) face |= B_REGULAR_FACE;
else if (weight >= 550 && weight < 650)
face |= B_CONDENSED_FACE;
#else
else if(weight >= 550 && weight < 650) face |= B_BOLD_FACE;
else if (weight >= 550 && weight < 650)
face |= B_BOLD_FACE;
#endif
else if(weight >= 650 && weight < 750) face |= B_BOLD_FACE;
else if (weight >= 650 && weight < 750)
face |= B_BOLD_FACE;
#ifndef __HAIKU__
else if(weight >= 750 && weight < 850) face |= B_BOLD_FACE;
else if(weight >= 950) face |= B_BOLD_FACE;
else if (weight >= 750 && weight < 850)
face |= B_BOLD_FACE;
else if (weight >= 950)
face |= B_BOLD_FACE;
#else
else if(weight >= 750 && weight < 850) face |= B_HEAVY_FACE;
else if(weight >= 950) face |= B_HEAVY_FACE;
else if (weight >= 750 && weight < 850)
face |= B_HEAVY_FACE;
else if (weight >= 950)
face |= B_HEAVY_FACE;
#endif
BFont* tempFont = new BFont();
bool found = false;
for(litehtml::string_vector::iterator i = fonts.begin();
i != fonts.end(); i++)
{
if (B_OK == tempFont->SetFamilyAndFace(i->c_str(),face))
{
found = true;
break;
}
}
BFont* tempFont = new BFont();
bool found = false;
for (litehtml::string_vector::iterator i = fonts.begin(); i != fonts.end(); i++) {
if (B_OK == tempFont->SetFamilyAndFace(i->c_str(), face)) {
found = true;
break;
}
}
if (!found)
{
// default to the Be plain font
tempFont = new BFont(be_plain_font);
if (weight >= 550)
{
tempFont = new BFont(be_bold_font);
}
tempFont->SetFace(face); // chooses closest
}
if (!found) {
// default to the Be plain font
tempFont = new BFont(be_plain_font);
if (weight >= 550) {
tempFont = new BFont(be_bold_font);
}
tempFont->SetFace(face); // chooses closest
}
tempFont->SetSize(size);
tempFont->SetSize(size);
font_height hgt;
tempFont->GetHeight(&hgt);
fm->ascent = hgt.ascent;
fm->descent = hgt.descent;
fm->height = (int) (hgt.ascent + hgt.descent);
fm->x_height = (int) hgt.leading;
font_height hgt;
tempFont->GetHeight(&hgt);
fm->ascent = hgt.ascent;
fm->descent = hgt.descent;
fm->height = (int)(hgt.ascent + hgt.descent);
fm->x_height = (int)hgt.leading;
return (litehtml::uint_ptr) tempFont;
return (litehtml::uint_ptr)tempFont;
}
void
LiteHtmlView::delete_font( litehtml::uint_ptr hFont )
{
std::cout << "delete_font" << std::endl;
void LiteHtmlView::delete_font(litehtml::uint_ptr hFont) { std::cout << "delete_font" << std::endl; }
int LiteHtmlView::text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) {
// std::cout << "text_width" << std::endl;
BFont* fnt = (BFont*)hFont;
int width = fnt->StringWidth(text);
// std::cout << " Width: " << +width << std::endl;
return width;
}
int
LiteHtmlView::text_width( const litehtml::tchar_t* text,
litehtml::uint_ptr hFont )
{
//std::cout << "text_width" << std::endl;
BFont* fnt = (BFont*)hFont;
int width = fnt->StringWidth(text);
//std::cout << " Width: " << +width << std::endl;
return width;
void LiteHtmlView::draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) {
// std::cout << "draw_text" << std::endl;
if (!text) return;
if (0 == strlen(text)) return;
BFont* fnt = (BFont*)hFont;
// std::cout << " left: " << +pos.left() << ", top: " << +pos.top() << std::endl;
// std::cout << " RGBA: " << +color.red << "," << +color.green << "," << +color.blue << "," << +color.alpha << std::endl;
// std::cout << " Font size: " << +fnt->Size() << std::endl;
// std::cout << " Text: " << text << std::endl;
BRect bounds(Bounds());
// FillRect(bounds,B_SOLID_LOW);
BPoint leftTop = bounds.LeftTop();
// std::cout << " Bounds left: " << +leftTop.x << ", top: " << +leftTop.y << ", Width: " << +bounds.Width() << ", Height: " << +bounds.Height() << std::endl;
font_height fh;
fnt->GetHeight(&fh);
int baseline = fh.ascent + fh.descent; // + 10;
int leftbase = 0; // 10;
MovePenTo(pos.left() + leftbase, pos.top() + baseline); // leftTop.x,leftTop.y);
SetFont(fnt);
// SetFont(be_plain_font);
rgb_color clr = ui_color(B_DOCUMENT_TEXT_COLOR);
/*
rgb_color clr;
clr.blue = 40;
clr.red = 40;
clr.green = 40;
*/
clr.red = color.red;
clr.green = color.green;
clr.blue = color.blue;
clr.alpha = color.alpha;
// std::cout << " Final RGBA: " << +clr.red << "," << +clr.green << "," << +clr.blue << "," << +clr.alpha << std::endl;
SetHighColor(clr);
SetLowColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
BString mystr("");
// mystr << "text: ";
mystr << text;
DrawString(mystr);
}
void
LiteHtmlView::draw_text( litehtml::uint_ptr hdc, const litehtml::tchar_t* text,
litehtml::uint_ptr hFont, litehtml::web_color color,
const litehtml::position& pos )
{
//std::cout << "draw_text" << std::endl;
if (!text) return;
if (0 == strlen(text)) return;
BFont* fnt = (BFont*)hFont;
//std::cout << " left: " << +pos.left() << ", top: " << +pos.top() << std::endl;
//std::cout << " RGBA: " << +color.red << "," << +color.green << "," << +color.blue << "," << +color.alpha << std::endl;
//std::cout << " Font size: " << +fnt->Size() << std::endl;
//std::cout << " Text: " << text << std::endl;
BRect bounds(Bounds());
//FillRect(bounds,B_SOLID_LOW);
BPoint leftTop = bounds.LeftTop();
//std::cout << " Bounds left: " << +leftTop.x << ", top: " << +leftTop.y << ", Width: " << +bounds.Width() << ", Height: " << +bounds.Height() << std::endl;
font_height fh;
fnt->GetHeight(&fh);
int baseline = fh.ascent + fh.descent;// + 10;
int leftbase = 0; //10;
MovePenTo(pos.left() + leftbase,pos.top() + baseline);//leftTop.x,leftTop.y);
SetFont(fnt);
//SetFont(be_plain_font);
rgb_color clr = ui_color(B_DOCUMENT_TEXT_COLOR);
/*
rgb_color clr;
clr.blue = 40;
clr.red = 40;
clr.green = 40;
*/
clr.red = color.red;
clr.green = color.green;
clr.blue = color.blue;
clr.alpha = color.alpha;
//std::cout << " Final RGBA: " << +clr.red << "," << +clr.green << "," << +clr.blue << "," << +clr.alpha << std::endl;
SetHighColor(clr);
SetLowColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
BString mystr("");
//mystr << "text: ";
mystr << text;
DrawString(mystr);
int LiteHtmlView::pt_to_px(int pt) {
std::cout << "pt_to_px" << std::endl;
return (int)((double)pt * 1.3333333333);
}
int
LiteHtmlView::pt_to_px( int pt )
{
std::cout << "pt_to_px" << std::endl;
return (int) ((double) pt * 1.3333333333);
int LiteHtmlView::get_default_font_size() const {
// std::cout << "get_default_font_size" << std::endl;
return 12;
}
int
LiteHtmlView::get_default_font_size() const
{
//std::cout << "get_default_font_size" << std::endl;
return 12;
const litehtml::tchar_t* LiteHtmlView::get_default_font_name() const {
// std::cout << "get_default_font_name" << std::endl;
font_family fam;
font_style style;
be_plain_font->GetFamilyAndStyle(&fam, &style);
char* cp = strdup(fam);
return (litehtml::tchar_t*)cp;
}
const litehtml::tchar_t*
LiteHtmlView::get_default_font_name() const
{
//std::cout << "get_default_font_name" << std::endl;
font_family fam;
font_style style;
be_plain_font->GetFamilyAndStyle(&fam,&style);
char* cp = strdup(fam);
return (litehtml::tchar_t*)cp;
void LiteHtmlView::draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) {
std::cout << "draw_list_marker" << std::endl;
if (!marker.image.empty()) {
std::cout << " image marker" << std::endl;
}
}
void
LiteHtmlView::draw_list_marker( litehtml::uint_ptr hdc,
const litehtml::list_marker& marker )
{
std::cout << "draw_list_marker" << std::endl;
if (!marker.image.empty())
{
std::cout << " image marker" << std::endl;
}
void LiteHtmlView::load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) {
std::cout << "load_image" << std::endl;
std::string url;
make_url(src, baseurl, url);
if (m_images.find(url.c_str()) == m_images.end()) {
BEntry entry(url.c_str(), true);
if (entry.Exists()) {
std::cout << " Loading bitmap from file" << std::endl;
BBitmap* img = BTranslationUtils::GetBitmap(url.c_str());
m_images[url] = img;
}
}
}
void
LiteHtmlView::load_image( const litehtml::tchar_t* src,
const litehtml::tchar_t* baseurl, bool redraw_on_ready )
{
std::cout << "load_image" << std::endl;
std::string url;
make_url(src, baseurl, url);
if(m_images.find(url.c_str()) == m_images.end())
{
BEntry entry(url.c_str(), true);
if (entry.Exists()) {
std::cout << " Loading bitmap from file" << std::endl;
BBitmap* img = BTranslationUtils::GetBitmap(url.c_str());
m_images[url] = img;
}
}
void LiteHtmlView::make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out) {
std::cout << "make_url" << std::endl;
std::cout << " url: " << url << std::endl;
if (!basepath || (basepath && !basepath[0])) {
if (!m_base_url.empty()) {
// out = urljoin(m_base_url, std::string(url));
std::string ns(m_base_url);
ns += "/";
ns += url;
out = ns;
} else {
out = url;
}
} else {
std::cout << " basepath: " << basepath << std::endl;
// out = urljoin(std::string(basepath), std::string(url));
std::string ns(basepath);
ns += "/";
ns += url;
out = ns;
}
std::cout << " Output url: " << out << std::endl;
}
void
LiteHtmlView::make_url(const litehtml::tchar_t* url,
const litehtml::tchar_t* basepath, litehtml::tstring& out)
{
std::cout << "make_url" << std::endl;
std::cout << " url: " << url << std::endl;
if(!basepath || (basepath && !basepath[0]))
{
if(!m_base_url.empty())
{
//out = urljoin(m_base_url, std::string(url));
std::string ns(m_base_url);
ns += "/";
ns += url;
out = ns;
} else
{
out = url;
}
} else
{
std::cout << " basepath: " << basepath << std::endl;
//out = urljoin(std::string(basepath), std::string(url));
std::string ns(basepath);
ns += "/";
ns += url;
out = ns;
}
std::cout << " Output url: " << out << std::endl;
void LiteHtmlView::set_base_url(const litehtml::tchar_t* base_url) {
std::cout << "set_base_url" << std::endl;
/*
if(base_url)
{
m_base_url = urljoin(m_url, std::string(base_url));
} else
{
*/
m_base_url = base_url;
std::cout << " base url set to: " << m_base_url << std::endl;
//}
}
void
LiteHtmlView::set_base_url(const litehtml::tchar_t* base_url)
{
std::cout << "set_base_url" << std::endl;
/*
if(base_url)
{
m_base_url = urljoin(m_url, std::string(base_url));
} else
{
*/
m_base_url = base_url;
std::cout << " base url set to: " << m_base_url << std::endl;
//}
void LiteHtmlView::get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) {
std::cout << "get_image_size" << std::endl;
std::string url;
make_url(src, NULL, url);
const auto& miter(m_images.find(url.c_str()));
if (m_images.end() != miter) {
BBitmap* img = (BBitmap*)miter->second;
BRect size = img->Bounds();
sz.width = size.Width();
sz.height = size.Height();
std::cout << " width: " << +sz.width << ", height: " << +sz.height << std::endl;
}
}
void
LiteHtmlView::get_image_size( const litehtml::tchar_t* src,
const litehtml::tchar_t* baseurl, litehtml::size& sz )
{
std::cout << "get_image_size" << std::endl;
std::string url;
make_url(src,NULL,url);
const auto& miter(m_images.find(url.c_str()));
if (m_images.end() != miter)
{
BBitmap* img = (BBitmap*)miter->second;
BRect size = img->Bounds();
sz.width = size.Width();
sz.height = size.Height();
std::cout << " width: " << +sz.width << ", height: " << +sz.height << std::endl;
}
void LiteHtmlView::draw_image(litehtml::uint_ptr hdc, const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, const litehtml::position& pos) {
std::string url;
make_url(src, baseurl, url);
const auto& img = m_images.find(url.c_str());
if (img != m_images.end()) {
if (img->second) {
DrawBitmap(img->second, BPoint(pos.x, pos.y)); // TODO support scaling
// draw_txdib(cr, img->second.get(), pos.x, pos.y, pos.width, pos.height);
}
}
}
void
LiteHtmlView::draw_image( litehtml::uint_ptr hdc, const litehtml::tchar_t* src,
const litehtml::tchar_t* baseurl, const litehtml::position& pos )
{
std::string url;
make_url(src, baseurl, url);
const auto& img = m_images.find(url.c_str());
if(img != m_images.end())
{
if(img->second)
{
DrawBitmap(img->second,BPoint(pos.x,pos.y)); // TODO support scaling
//draw_txdib(cr, img->second.get(), pos.x, pos.y, pos.width, pos.height);
}
}
void LiteHtmlView::draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) {
std::cout << "draw_background" << std::endl;
if (0 < bg.image.length()) {
std::cout << " background includes an image!" << std::endl;
draw_image(hdc, bg.image.c_str(), m_base_url.c_str(), litehtml::position(bg.position_x, bg.position_y, bg.image_size.width, bg.image_size.height));
}
}
void
LiteHtmlView::draw_background( litehtml::uint_ptr hdc,
const litehtml::background_paint& bg )
{
std::cout << "draw_background" << std::endl;
if (0 < bg.image.length())
{
std::cout << " background includes an image!" << std::endl;
draw_image(hdc,bg.image.c_str(),m_base_url.c_str(),litehtml::position(bg.position_x,bg.position_y,bg.image_size.width,bg.image_size.height));
}
void LiteHtmlView::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) {
std::cout << "draw_borders" << std::endl;
int bdr_top = 0;
int bdr_bottom = 0;
int bdr_left = 0;
int bdr_right = 0;
// std::cout << " uint ptr: " << +hdc << std::endl;
// std::cout << " this ptr: " << +this << std::endl;
if (borders.top.width != 0 && borders.top.style > litehtml::border_style_hidden) {
bdr_top = (int)borders.top.width;
std::cout << " Border top: " << bdr_right << std::endl;
}
if (borders.bottom.width != 0 && borders.bottom.style > litehtml::border_style_hidden) {
bdr_bottom = (int)borders.bottom.width;
std::cout << " Border bottom: " << bdr_right << std::endl;
}
if (borders.left.width != 0 && borders.left.style > litehtml::border_style_hidden) {
bdr_left = (int)borders.left.width;
std::cout << " Border left: " << bdr_right << std::endl;
}
if (borders.right.width != 0 && borders.right.style > litehtml::border_style_hidden) {
bdr_right = (int)borders.right.width;
std::cout << " Border right: " << bdr_right << std::endl;
}
if (bdr_bottom) {
// draw rectangle for now - no check for radius
StrokeRect(BRect(BPoint(draw_pos.left(), draw_pos.bottom()), BPoint(draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom)));
}
}
void
LiteHtmlView::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root)
{
std::cout << "draw_borders" << std::endl;
int bdr_top = 0;
int bdr_bottom = 0;
int bdr_left = 0;
int bdr_right = 0;
void LiteHtmlView::transform_text(litehtml::tstring& text, litehtml::text_transform tt) { std::cout << "transform_text" << std::endl; }
//std::cout << " uint ptr: " << +hdc << std::endl;
//std::cout << " this ptr: " << +this << std::endl;
void LiteHtmlView::set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) { std::cout << "set_clip" << std::endl; }
if(borders.top.width != 0 && borders.top.style > litehtml::border_style_hidden)
{
bdr_top = (int) borders.top.width;
std::cout << " Border top: " << bdr_right << std::endl;
}
if(borders.bottom.width != 0 && borders.bottom.style > litehtml::border_style_hidden)
{
bdr_bottom = (int) borders.bottom.width;
std::cout << " Border bottom: " << bdr_right << std::endl;
}
if(borders.left.width != 0 && borders.left.style > litehtml::border_style_hidden)
{
bdr_left = (int) borders.left.width;
std::cout << " Border left: " << bdr_right << std::endl;
}
if(borders.right.width != 0 && borders.right.style > litehtml::border_style_hidden)
{
bdr_right = (int) borders.right.width;
std::cout << " Border right: " << bdr_right << std::endl;
}
void LiteHtmlView::del_clip() { std::cout << "del_clip" << std::endl; }
if (bdr_bottom)
{
// draw rectangle for now - no check for radius
StrokeRect(
BRect(
BPoint(draw_pos.left(), draw_pos.bottom()),
BPoint(draw_pos.left() + bdr_left, draw_pos.bottom() - bdr_bottom)
)
);
}
std::shared_ptr<litehtml::element> LiteHtmlView::create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) {
// std::cout << "create_element" << std::endl;
return 0;
}
void
LiteHtmlView::transform_text(litehtml::tstring& text, litehtml::text_transform tt)
{
std::cout << "transform_text" << std::endl;
void LiteHtmlView::get_media_features(litehtml::media_features& media) const {
std::cout << "get_media_features" << std::endl;
litehtml::position client;
get_client_rect(client);
media.type = litehtml::media_type_screen;
media.width = client.width;
media.height = client.height;
BRect bounds(Bounds());
media.device_width = bounds.Width();
media.device_height = bounds.Height();
media.color = 8;
media.monochrome = 0;
media.color_index = 256;
media.resolution = 96;
}
void
LiteHtmlView::set_clip( const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y )
{
std::cout << "set_clip" << std::endl;
void LiteHtmlView::link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) { std::cout << "link" << std::endl; }
void LiteHtmlView::set_caption(const char* caption) { std::cout << "set_caption" << std::endl; }
void LiteHtmlView::get_client_rect(litehtml::position& client) const {
// std::cout << "get_client_rect" << std::endl;
BRect bounds(Bounds());
BPoint leftTop = bounds.LeftTop();
client.width = bounds.Width();
client.height = bounds.Height();
client.x = leftTop.x;
client.y = leftTop.y;
}
void
LiteHtmlView::del_clip()
{
std::cout << "del_clip" << std::endl;
}
void LiteHtmlView::on_anchor_click(const char* base, const litehtml::element::ptr& anchor) { std::cout << "on_anchor_click" << std::endl; }
void LiteHtmlView::set_cursor(const char* cursor) { std::cout << "set_cursor" << std::endl; }
void LiteHtmlView::import_css(litehtml::tstring& s1, const litehtml::tstring& s2, litehtml::tstring& s3) { std::cout << "import_css" << std::endl; }
std::shared_ptr<litehtml::element>
LiteHtmlView::create_element(const litehtml::tchar_t *tag_name,
const litehtml::string_map &attributes,
const std::shared_ptr<litehtml::document> &doc)
{
//std::cout << "create_element" << std::endl;
return 0;
}
void
LiteHtmlView::get_media_features(litehtml::media_features& media) const
{
std::cout << "get_media_features" << std::endl;
litehtml::position client;
get_client_rect(client);
media.type = litehtml::media_type_screen;
media.width = client.width;
media.height = client.height;
BRect bounds(Bounds());
media.device_width = bounds.Width();
media.device_height = bounds.Height();
media.color = 8;
media.monochrome = 0;
media.color_index = 256;
media.resolution = 96;
}
void
LiteHtmlView::link(const std::shared_ptr<litehtml::document> &ptr, const litehtml::element::ptr& el)
{
std::cout << "link" << std::endl;
}
void
LiteHtmlView::set_caption(const char* caption)
{
std::cout << "set_caption" << std::endl;
}
void
LiteHtmlView::get_client_rect(litehtml::position& client) const
{
//std::cout << "get_client_rect" << std::endl;
BRect bounds(Bounds());
BPoint leftTop = bounds.LeftTop();
client.width = bounds.Width();
client.height = bounds.Height();
client.x = leftTop.x;
client.y = leftTop.y;
}
void
LiteHtmlView::on_anchor_click(const char* base, const litehtml::element::ptr& anchor)
{
std::cout << "on_anchor_click" << std::endl;
}
void
LiteHtmlView::set_cursor(const char* cursor)
{
std::cout << "set_cursor" << std::endl;
}
void
LiteHtmlView::import_css(litehtml::tstring& s1, const litehtml::tstring& s2, litehtml::tstring& s3)
{
std::cout << "import_css" << std::endl;
}
void
LiteHtmlView::get_language(litehtml::tstring& s1, litehtml::tstring& s2) const
{
std::cout << "get_language" << std::endl;
}
void LiteHtmlView::get_language(litehtml::tstring& s1, litehtml::tstring& s2) const { std::cout << "get_language" << std::endl; }

View file

@ -7,81 +7,73 @@
#ifndef LITEHTMLVIEW_H
#define LITEHTMLVIEW_H
#include "../../include/litehtml.h"
#include <View.h>
#include <map>
#include <string>
#include <View.h>
#include "../../include/litehtml.h"
class BBitmap;
enum { M_HTML_RENDERED = 'hrnd' };
enum {
M_HTML_RENDERED = 'hrnd'
};
class LiteHtmlView : public BView, public litehtml::document_container {
public:
// LiteHtmlView(BMessage *archive);
LiteHtmlView(BRect frame, const char* name);
// LiteHtmlView(const char *name, uint32 flags, BLayout *layout=NULL);
class LiteHtmlView : public BView, public litehtml::document_container
{
public:
//LiteHtmlView(BMessage *archive);
LiteHtmlView(BRect frame, const char *name);
//LiteHtmlView(const char *name, uint32 flags, BLayout *layout=NULL);
virtual ~LiteHtmlView();
virtual ~LiteHtmlView();
void SetContext(litehtml::context* ctx);
void RenderFile(const char* localFilePath);
void RenderHTML(const std::string& htmlText);
void SetContext(litehtml::context* ctx);
void RenderFile(const char* localFilePath);
void RenderHTML(const std::string& htmlText);
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
virtual void delete_font(litehtml::uint_ptr hFont) override;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
virtual int pt_to_px(int pt) override;
virtual int get_default_font_size() const override;
virtual const litehtml::tchar_t* get_default_font_name() const override;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
virtual void get_media_features(litehtml::media_features& media) const override;
// virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const override;
virtual void link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) override;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
virtual void del_clip() override;
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
virtual void delete_font(litehtml::uint_ptr hFont) override;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
virtual int pt_to_px(int pt) override;
virtual int get_default_font_size() const override;
virtual const litehtml::tchar_t* get_default_font_name() const override;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
const litehtml::string_map &attributes,
const std::shared_ptr<litehtml::document> &doc) override;
virtual void get_media_features(litehtml::media_features& media) const override;
//virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const override;
virtual void link(const std::shared_ptr<litehtml::document> &ptr, const litehtml::element::ptr& el) override;
// unimplemented
virtual void set_caption(const char*);
virtual void get_client_rect(litehtml::position& client) const;
virtual void set_base_url(const char*);
virtual void on_anchor_click(const char*, const litehtml::element::ptr&);
virtual void set_cursor(const char*);
virtual void import_css(litehtml::tstring&, const litehtml::tstring&, litehtml::tstring&);
virtual void get_language(litehtml::tstring&, litehtml::tstring&) const;
// BView
virtual void Draw(BRect updateRect) override;
virtual void GetPreferredSize(float* width, float* height) override;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
virtual void del_clip() override;
protected:
void make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out);
virtual void draw_image(litehtml::uint_ptr hdc, const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, const litehtml::position& pos);
// unimplemented
virtual void set_caption(const char*);
virtual void get_client_rect(litehtml::position& client) const;
virtual void set_base_url(const char*);
virtual void on_anchor_click(const char*, const litehtml::element::ptr&);
virtual void set_cursor(const char*);
virtual void import_css(litehtml::tstring&, const litehtml::tstring&, litehtml::tstring&);
virtual void get_language(litehtml::tstring&, litehtml::tstring&) const;
//BView
virtual void Draw(BRect updateRect) override;
virtual void GetPreferredSize(float* width, float* height) override;
protected:
void make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out);
virtual void draw_image( litehtml::uint_ptr hdc, const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, const litehtml::position& pos );
private:
litehtml::context* fContext;
litehtml::document::ptr m_html;
std::map<const std::string,BBitmap*> m_images;
litehtml::tstring m_base_url;
litehtml::tstring m_url;
private:
litehtml::context* fContext;
litehtml::document::ptr m_html;
std::map<const std::string, BBitmap*> m_images;
litehtml::tstring m_base_url;
litehtml::tstring m_url;
};
#endif

View file

@ -1,104 +1,97 @@
#ifndef LH_CONTAINER_LINUX_H
#define LH_CONTAINER_LINUX_H
#include "../../include/litehtml.h"
#include <cairo.h>
#include <gtkmm.h>
#include <pango/pangocairo.h>
struct cairo_clip_box
{
typedef std::vector<cairo_clip_box> vector;
litehtml::position box;
litehtml::border_radiuses radius;
#include "../../include/litehtml.h"
cairo_clip_box(const litehtml::position& vBox, const litehtml::border_radiuses& vRad)
{
box = vBox;
radius = vRad;
}
struct cairo_clip_box {
typedef std::vector<cairo_clip_box> vector;
litehtml::position box;
litehtml::border_radiuses radius;
cairo_clip_box(const cairo_clip_box& val)
{
box = val.box;
radius = val.radius;
}
cairo_clip_box& operator=(const cairo_clip_box& val)
{
box = val.box;
radius = val.radius;
return *this;
}
cairo_clip_box(const litehtml::position& vBox, const litehtml::border_radiuses& vRad) {
box = vBox;
radius = vRad;
}
cairo_clip_box(const cairo_clip_box& val) {
box = val.box;
radius = val.radius;
}
cairo_clip_box& operator=(const cairo_clip_box& val) {
box = val.box;
radius = val.radius;
return *this;
}
};
struct cairo_font
{
PangoFontDescription* font;
int size;
bool underline;
bool strikeout;
int ascent;
int descent;
int underline_thickness;
int underline_position;
int strikethrough_thickness;
int strikethrough_position;
struct cairo_font {
PangoFontDescription* font;
int size;
bool underline;
bool strikeout;
int ascent;
int descent;
int underline_thickness;
int underline_position;
int strikethrough_thickness;
int strikethrough_position;
};
class container_linux : public litehtml::document_container
{
typedef std::map<litehtml::tstring, Glib::RefPtr<Gdk::Pixbuf> > images_map;
class container_linux : public litehtml::document_container {
typedef std::map<litehtml::tstring, Glib::RefPtr<Gdk::Pixbuf> > images_map;
protected:
cairo_surface_t* m_temp_surface;
cairo_t* m_temp_cr;
images_map m_images;
cairo_clip_box::vector m_clips;
public:
container_linux();
virtual ~container_linux();
protected:
cairo_surface_t* m_temp_surface;
cairo_t* m_temp_cr;
images_map m_images;
cairo_clip_box::vector m_clips;
litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
void delete_font(litehtml::uint_ptr hFont) override;
int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
int pt_to_px(int pt) const override;
int get_default_font_size() const override;
const litehtml::tchar_t* get_default_font_name() const override;
void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
const litehtml::string_map &attributes,
const std::shared_ptr<litehtml::document> &doc) override;
void get_media_features(litehtml::media_features& media) const override;
void get_language(litehtml::tstring& language, litehtml::tstring & culture) const override;
void link(const std::shared_ptr<litehtml::document> &ptr, const litehtml::element::ptr& el) override;
public:
container_linux();
virtual ~container_linux();
litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
void delete_font(litehtml::uint_ptr hFont) override;
int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
int pt_to_px(int pt) const override;
int get_default_font_size() const override;
const litehtml::tchar_t* get_default_font_name() const override;
void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
void get_media_features(litehtml::media_features& media) const override;
void get_language(litehtml::tstring& language, litehtml::tstring& culture) const override;
void link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) override;
void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
void del_clip() override;
void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
void del_clip() override;
virtual void make_url( const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out );
virtual Glib::RefPtr<Gdk::Pixbuf> get_image(const litehtml::tchar_t* url, bool redraw_on_ready) = 0;
virtual void make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out);
virtual Glib::RefPtr<Gdk::Pixbuf> get_image(const litehtml::tchar_t* url, bool redraw_on_ready) = 0;
void clear_images();
void clear_images();
protected:
virtual void draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
virtual void fill_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color);
virtual void rounded_rectangle( cairo_t* cr, const litehtml::position &pos, const litehtml::border_radiuses &radius );
protected:
virtual void draw_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color, int line_width);
virtual void fill_ellipse(cairo_t* cr, int x, int y, int width, int height, const litehtml::web_color& color);
virtual void rounded_rectangle(cairo_t* cr, const litehtml::position& pos, const litehtml::border_radiuses& radius);
private:
void apply_clip(cairo_t* cr);
private:
void apply_clip(cairo_t* cr);
static void add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg);
static void set_color(cairo_t* cr, const litehtml::web_color& color) { cairo_set_source_rgba(cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0, color.alpha / 255.0); }
static cairo_surface_t* surface_from_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& bmp);
static void draw_pixbuf(cairo_t* cr, const Glib::RefPtr<Gdk::Pixbuf>& bmp, int x, int y, int cx, int cy);
static void add_path_arc(cairo_t* cr, double x, double y, double rx, double ry, double a1, double a2, bool neg);
static void set_color(cairo_t* cr, const litehtml::web_color& color) { cairo_set_source_rgba(cr, color.red / 255.0, color.green / 255.0, color.blue / 255.0, color.alpha / 255.0); }
static cairo_surface_t* surface_from_pixbuf(const Glib::RefPtr<Gdk::Pixbuf>& bmp);
static void draw_pixbuf(cairo_t* cr, const Glib::RefPtr<Gdk::Pixbuf>& bmp, int x, int y, int cx, int cy);
};
#endif

View file

@ -23,8 +23,8 @@ void container_test::get_image_size(const litehtml::tchar_t* src, const litehtml
void container_test::draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) {}
void container_test::make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out) { out = url; }
void container_test::draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) {}
void container_test::set_caption(const litehtml::tchar_t* caption){}; //: set_caption
void container_test::set_base_url(const litehtml::tchar_t* base_url){}; //: set_base_url
void container_test::set_caption(const litehtml::tchar_t* caption) {}; //: set_caption
void container_test::set_base_url(const litehtml::tchar_t* base_url) {}; //: set_base_url
void container_test::link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) {}
void container_test::on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) {} //: on_anchor_click
void container_test::set_cursor(const litehtml::tchar_t* cursor) {} //: set_cursor

View file

@ -2,43 +2,38 @@
#include "../../include/litehtml.h"
class container_test : public litehtml::document_container
{
public:
container_test();
virtual ~container_test();
class container_test : public litehtml::document_container {
public:
container_test();
virtual ~container_test();
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
virtual void delete_font(litehtml::uint_ptr hFont) override;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
virtual int pt_to_px(int pt) const override;
virtual int get_default_font_size() const override;
virtual const litehtml::tchar_t* get_default_font_name() const override;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
const litehtml::string_map &attributes,
const std::shared_ptr<litehtml::document> &doc) override;
virtual void get_media_features(litehtml::media_features& media) const override;
virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const override;
virtual void link(const std::shared_ptr<litehtml::document> &ptr, const litehtml::element::ptr& el) override;
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) override;
virtual void delete_font(litehtml::uint_ptr hFont) override;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) override;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) override;
virtual int pt_to_px(int pt) const override;
virtual int get_default_font_size() const override;
virtual const litehtml::tchar_t* get_default_font_name() const override;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) override;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) override;
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) override;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) override;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) override;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) override;
virtual void get_media_features(litehtml::media_features& media) const override;
virtual void get_language(litehtml::tstring& language, litehtml::tstring& culture) const override;
virtual void link(const std::shared_ptr<litehtml::document>& ptr, const litehtml::element::ptr& el) override;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
virtual void del_clip() override;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) override;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) override;
virtual void del_clip() override;
virtual void make_url(const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out);
virtual void make_url( const litehtml::tchar_t* url, const litehtml::tchar_t* basepath, litehtml::tstring& out );
virtual void set_caption(const litehtml::tchar_t* caption) override;
virtual void set_base_url(const litehtml::tchar_t* base_url) override;
virtual void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) override;
virtual void set_cursor(const litehtml::tchar_t* cursor) override;
virtual void import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl) override;
virtual void get_client_rect(litehtml::position& client) const override;
virtual void set_caption(const litehtml::tchar_t* caption) override;
virtual void set_base_url(const litehtml::tchar_t* base_url) override;
virtual void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) override;
virtual void set_cursor(const litehtml::tchar_t* cursor) override;
virtual void import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl) override;
virtual void get_client_rect(litehtml::position& client) const override;
};

View file

@ -1,327 +1,259 @@
#include <litehtml.h>
#include "win32_container.h"
#include <litehtml.h>
litehtml::win32_container::win32_container()
{
m_hClipRgn = NULL;
litehtml::win32_container::win32_container() { m_hClipRgn = NULL; }
litehtml::win32_container::~win32_container() {
if (m_hClipRgn) {
DeleteObject(m_hClipRgn);
}
}
litehtml::win32_container::~win32_container()
{
if(m_hClipRgn)
{
DeleteObject(m_hClipRgn);
}
litehtml::uint_ptr litehtml::win32_container::create_font(const wchar_t* faceName, int size, int weight, font_style italic, unsigned int decoration) {
litehtml::string_vector fonts;
tokenize(faceName, fonts, L",");
litehtml::trim(fonts[0]);
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
wcscpy_s(lf.lfFaceName, LF_FACESIZE, fonts[0].c_str());
lf.lfHeight = -size;
lf.lfWeight = weight;
lf.lfItalic = (italic == litehtml::fontStyleItalic) ? TRUE : FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfStrikeOut = (decoration & litehtml::font_decoration_linethrough) ? TRUE : FALSE;
lf.lfUnderline = (decoration & litehtml::font_decoration_underline) ? TRUE : FALSE;
HFONT hFont = CreateFontIndirect(&lf);
return (uint_ptr)hFont;
}
litehtml::uint_ptr litehtml::win32_container::create_font( const wchar_t* faceName, int size, int weight, font_style italic, unsigned int decoration )
{
litehtml::string_vector fonts;
tokenize(faceName, fonts, L",");
litehtml::trim(fonts[0]);
void litehtml::win32_container::delete_font(uint_ptr hFont) { DeleteObject((HFONT)hFont); }
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
wcscpy_s(lf.lfFaceName, LF_FACESIZE, fonts[0].c_str());
lf.lfHeight = -size;
lf.lfWeight = weight;
lf.lfItalic = (italic == litehtml::fontStyleItalic) ? TRUE : FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfStrikeOut = (decoration & litehtml::font_decoration_linethrough) ? TRUE : FALSE;
lf.lfUnderline = (decoration & litehtml::font_decoration_underline) ? TRUE : FALSE;
HFONT hFont = CreateFontIndirect(&lf);
return (uint_ptr) hFont;
int litehtml::win32_container::line_height(uint_ptr hdc, uint_ptr hFont) {
HFONT oldFont = (HFONT)SelectObject((HDC)hdc, (HFONT)hFont);
TEXTMETRIC tm;
GetTextMetrics((HDC)hdc, &tm);
SelectObject((HDC)hdc, oldFont);
return (int)tm.tmHeight;
}
void litehtml::win32_container::delete_font( uint_ptr hFont )
{
DeleteObject((HFONT) hFont);
int litehtml::win32_container::text_width(uint_ptr hdc, const wchar_t* text, uint_ptr hFont) {
HFONT oldFont = (HFONT)SelectObject((HDC)hdc, (HFONT)hFont);
SIZE sz = {0, 0};
GetTextExtentPoint32((HDC)hdc, text, lstrlen(text), &sz);
SelectObject((HDC)hdc, oldFont);
return (int)sz.cx;
}
int litehtml::win32_container::line_height( uint_ptr hdc, uint_ptr hFont )
{
HFONT oldFont = (HFONT) SelectObject((HDC) hdc, (HFONT) hFont);
TEXTMETRIC tm;
GetTextMetrics((HDC) hdc, &tm);
SelectObject((HDC) hdc, oldFont);
return (int) tm.tmHeight;
void litehtml::win32_container::draw_text(uint_ptr hdc, const wchar_t* text, uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) {
apply_clip((HDC)hdc);
HFONT oldFont = (HFONT)SelectObject((HDC)hdc, (HFONT)hFont);
SetBkMode((HDC)hdc, TRANSPARENT);
SetTextColor((HDC)hdc, RGB(color.red, color.green, color.blue));
RECT rcText = {pos.left(), pos.top(), pos.right(), pos.bottom()};
DrawText((HDC)hdc, text, -1, &rcText, DT_SINGLELINE | DT_NOPREFIX | DT_BOTTOM | DT_NOCLIP);
SelectObject((HDC)hdc, oldFont);
release_clip((HDC)hdc);
}
int litehtml::win32_container::text_width( uint_ptr hdc, const wchar_t* text, uint_ptr hFont )
{
HFONT oldFont = (HFONT) SelectObject((HDC) hdc, (HFONT) hFont);
SIZE sz = {0, 0};
GetTextExtentPoint32((HDC) hdc, text, lstrlen(text), &sz);
SelectObject((HDC) hdc, oldFont);
return (int) sz.cx;
void litehtml::win32_container::fill_rect(uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius) {
apply_clip((HDC)hdc);
fill_rect((HDC)hdc, pos.x, pos.y, pos.width, pos.height, color, radius);
release_clip((HDC)hdc);
}
void litehtml::win32_container::draw_text( uint_ptr hdc, const wchar_t* text, uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos )
{
apply_clip((HDC) hdc);
litehtml::uint_ptr litehtml::win32_container::get_temp_dc() { return (litehtml::uint_ptr)GetDC(NULL); }
HFONT oldFont = (HFONT) SelectObject((HDC) hdc, (HFONT) hFont);
void litehtml::win32_container::release_temp_dc(uint_ptr hdc) { ReleaseDC(NULL, (HDC)hdc); }
SetBkMode((HDC) hdc, TRANSPARENT);
SetTextColor((HDC) hdc, RGB(color.red, color.green, color.blue));
RECT rcText = { pos.left(), pos.top(), pos.right(), pos.bottom() };
DrawText((HDC) hdc, text, -1, &rcText, DT_SINGLELINE | DT_NOPREFIX | DT_BOTTOM | DT_NOCLIP);
SelectObject((HDC) hdc, oldFont);
release_clip((HDC) hdc);
int litehtml::win32_container::pt_to_px(int pt) {
HDC dc = GetDC(NULL);
int ret = MulDiv(pt, GetDeviceCaps(dc, LOGPIXELSY), 72);
ReleaseDC(NULL, dc);
return ret;
}
void litehtml::win32_container::fill_rect( uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius )
{
apply_clip((HDC) hdc);
fill_rect((HDC) hdc, pos.x, pos.y, pos.width, pos.height, color, radius);
release_clip((HDC) hdc);
int litehtml::win32_container::get_text_base_line(uint_ptr hdc, uint_ptr hFont) {
HDC dc = (HDC)hdc;
if (!dc) {
dc = GetDC(NULL);
}
HFONT oldFont = (HFONT)SelectObject(dc, (HFONT)hFont);
TEXTMETRIC tm;
GetTextMetrics(dc, &tm);
SelectObject(dc, oldFont);
if (!hdc) {
ReleaseDC(NULL, dc);
}
return (int)tm.tmDescent;
}
litehtml::uint_ptr litehtml::win32_container::get_temp_dc()
{
return (litehtml::uint_ptr) GetDC(NULL);
void litehtml::win32_container::draw_list_marker(uint_ptr hdc, const litehtml::list_marker& marker) {
apply_clip((HDC)hdc);
int top_margin = marker.pos.height / 3;
if (top_margin < 4) top_margin = 0;
int draw_x = marker.pos.x;
int draw_y = marker.pos.y + top_margin;
int draw_width = marker.pos.height - top_margin * 2;
int draw_height = marker.pos.height - top_margin * 2;
switch (marker.marker_type) {
case list_style_type_circle: {
draw_ellipse((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color, 1);
} break;
case list_style_type_disc: {
fill_ellipse((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color);
} break;
case list_style_type_square: {
fill_rect((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color, css_border_radius());
} break;
}
release_clip((HDC)hdc);
}
void litehtml::win32_container::release_temp_dc( uint_ptr hdc )
{
ReleaseDC(NULL, (HDC) hdc);
void litehtml::win32_container::load_image(const wchar_t* src, const wchar_t* baseurl, bool redraw_on_ready) {
std::wstring url;
make_url(src, baseurl, url);
if (m_images.find(url.c_str()) == m_images.end()) {
uint_ptr img = get_image(url.c_str());
if (img) {
m_images[url.c_str()] = img;
}
}
}
int litehtml::win32_container::pt_to_px( int pt )
{
HDC dc = GetDC(NULL);
int ret = MulDiv(pt, GetDeviceCaps(dc, LOGPIXELSY), 72);
ReleaseDC(NULL, dc);
return ret;
void litehtml::win32_container::get_image_size(const wchar_t* src, const wchar_t* baseurl, litehtml::size& sz) {
std::wstring url;
make_url(src, baseurl, url);
images_map::iterator img = m_images.find(url.c_str());
if (img != m_images.end()) {
get_img_size(img->second, sz);
}
}
int litehtml::win32_container::get_text_base_line( uint_ptr hdc, uint_ptr hFont )
{
HDC dc = (HDC) hdc;
if(!dc)
{
dc = GetDC(NULL);
}
HFONT oldFont = (HFONT) SelectObject(dc, (HFONT) hFont);
TEXTMETRIC tm;
GetTextMetrics(dc, &tm);
SelectObject(dc, oldFont);
if(!hdc)
{
ReleaseDC(NULL, dc);
}
return (int) tm.tmDescent;
void litehtml::win32_container::draw_image(uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos) {
apply_clip((HDC)hdc);
std::wstring url;
make_url(src, baseurl, url);
images_map::iterator img = m_images.find(url.c_str());
if (img != m_images.end()) {
draw_img((HDC)hdc, img->second, pos);
}
release_clip((HDC)hdc);
}
void litehtml::win32_container::draw_list_marker(uint_ptr hdc, const litehtml::list_marker& marker)
{
apply_clip((HDC)hdc);
int top_margin = marker.pos.height / 3;
if (top_margin < 4)
top_margin = 0;
int draw_x = marker.pos.x;
int draw_y = marker.pos.y + top_margin;
int draw_width = marker.pos.height - top_margin * 2;
int draw_height = marker.pos.height - top_margin * 2;
switch (marker.marker_type)
{
case list_style_type_circle:
{
draw_ellipse((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color, 1);
}
break;
case list_style_type_disc:
{
fill_ellipse((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color);
}
break;
case list_style_type_square:
{
fill_rect((HDC)hdc, draw_x, draw_y, draw_width, draw_height, marker.color, css_border_radius());
}
break;
}
release_clip((HDC)hdc);
void litehtml::win32_container::clear_images() {
for (images_map::iterator i = m_images.begin(); i != m_images.end(); i++) {
if (i->second) {
free_image(i->second);
}
}
m_images.clear();
}
void litehtml::win32_container::load_image( const wchar_t* src, const wchar_t* baseurl, bool redraw_on_ready )
{
std::wstring url;
make_url(src, baseurl, url);
if(m_images.find(url.c_str()) == m_images.end())
{
uint_ptr img = get_image(url.c_str());
if(img)
{
m_images[url.c_str()] = img;
}
}
int litehtml::win32_container::get_default_font_size() const { return 16; }
void litehtml::win32_container::draw_background(uint_ptr hdc, const wchar_t* image, const wchar_t* baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment) {
apply_clip((HDC)hdc);
std::wstring url;
make_url(image, baseurl, url);
images_map::iterator img = m_images.find(url.c_str());
if (img != m_images.end()) {
litehtml::size img_sz;
get_img_size(img->second, img_sz);
litehtml::position pos = draw_pos;
if (bg_pos.x.units() != css_units_percentage) {
pos.x += (int)bg_pos.x.val();
} else {
pos.x += (int)((float)(draw_pos.width - img_sz.width) * bg_pos.x.val() / 100.0);
}
if (bg_pos.y.units() != css_units_percentage) {
pos.y += (int)bg_pos.y.val();
} else {
pos.y += (int)((float)(draw_pos.height - img_sz.height) * bg_pos.y.val() / 100.0);
}
draw_img_bg((HDC)hdc, img->second, draw_pos, pos, repeat, attachment);
}
release_clip((HDC)hdc);
}
void litehtml::win32_container::get_image_size( const wchar_t* src, const wchar_t* baseurl, litehtml::size& sz )
{
std::wstring url;
make_url(src, baseurl, url);
wchar_t litehtml::win32_container::toupper(const wchar_t c) { return (wchar_t)CharUpper((LPWSTR)c); }
images_map::iterator img = m_images.find(url.c_str());
if(img != m_images.end())
{
get_img_size(img->second, sz);
}
wchar_t litehtml::win32_container::tolower(const wchar_t c) { return (wchar_t)CharLower((LPWSTR)c); }
void litehtml::win32_container::set_clip(const litehtml::position& pos, bool valid_x, bool valid_y) {
litehtml::position clip_pos = pos;
litehtml::position client_pos;
get_client_rect(client_pos);
if (!valid_x) {
clip_pos.x = client_pos.x;
clip_pos.width = client_pos.width;
}
if (!valid_y) {
clip_pos.y = client_pos.y;
clip_pos.height = client_pos.height;
}
m_clips.push_back(clip_pos);
}
void litehtml::win32_container::draw_image( uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos )
{
apply_clip((HDC) hdc);
std::wstring url;
make_url(src, baseurl, url);
images_map::iterator img = m_images.find(url.c_str());
if(img != m_images.end())
{
draw_img((HDC) hdc, img->second, pos);
}
release_clip((HDC) hdc);
void litehtml::win32_container::del_clip() {
if (!m_clips.empty()) {
m_clips.pop_back();
if (!m_clips.empty()) {
litehtml::position clip_pos = m_clips.back();
}
}
}
void litehtml::win32_container::clear_images()
{
for(images_map::iterator i = m_images.begin(); i != m_images.end(); i++)
{
if(i->second)
{
free_image(i->second);
}
}
m_images.clear();
void litehtml::win32_container::apply_clip(HDC hdc) {
if (m_hClipRgn) {
DeleteObject(m_hClipRgn);
m_hClipRgn = NULL;
}
if (!m_clips.empty()) {
POINT ptView = {0, 0};
GetWindowOrgEx(hdc, &ptView);
litehtml::position clip_pos = m_clips.back();
m_hClipRgn = CreateRectRgn(clip_pos.left() - ptView.x, clip_pos.top() - ptView.y, clip_pos.right() - ptView.x, clip_pos.bottom() - ptView.y);
SelectClipRgn(hdc, m_hClipRgn);
}
}
int litehtml::win32_container::get_default_font_size() const
{
return 16;
}
void litehtml::win32_container::draw_background( uint_ptr hdc, const wchar_t* image, const wchar_t* baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment )
{
apply_clip((HDC) hdc);
std::wstring url;
make_url(image, baseurl, url);
images_map::iterator img = m_images.find(url.c_str());
if(img != m_images.end())
{
litehtml::size img_sz;
get_img_size(img->second, img_sz);
litehtml::position pos = draw_pos;
if(bg_pos.x.units() != css_units_percentage)
{
pos.x += (int) bg_pos.x.val();
} else
{
pos.x += (int) ((float) (draw_pos.width - img_sz.width) * bg_pos.x.val() / 100.0);
}
if(bg_pos.y.units() != css_units_percentage)
{
pos.y += (int) bg_pos.y.val();
} else
{
pos.y += (int) ( (float) (draw_pos.height - img_sz.height) * bg_pos.y.val() / 100.0);
}
draw_img_bg((HDC) hdc, img->second, draw_pos, pos, repeat, attachment);
}
release_clip((HDC) hdc);
}
wchar_t litehtml::win32_container::toupper( const wchar_t c )
{
return (wchar_t) CharUpper((LPWSTR) c);
}
wchar_t litehtml::win32_container::tolower( const wchar_t c )
{
return (wchar_t) CharLower((LPWSTR) c);
}
void litehtml::win32_container::set_clip( const litehtml::position& pos, bool valid_x, bool valid_y )
{
litehtml::position clip_pos = pos;
litehtml::position client_pos;
get_client_rect(client_pos);
if(!valid_x)
{
clip_pos.x = client_pos.x;
clip_pos.width = client_pos.width;
}
if(!valid_y)
{
clip_pos.y = client_pos.y;
clip_pos.height = client_pos.height;
}
m_clips.push_back(clip_pos);
}
void litehtml::win32_container::del_clip()
{
if(!m_clips.empty())
{
m_clips.pop_back();
if(!m_clips.empty())
{
litehtml::position clip_pos = m_clips.back();
}
}
}
void litehtml::win32_container::apply_clip(HDC hdc)
{
if(m_hClipRgn)
{
DeleteObject(m_hClipRgn);
m_hClipRgn = NULL;
}
if(!m_clips.empty())
{
POINT ptView = {0, 0};
GetWindowOrgEx(hdc, &ptView);
litehtml::position clip_pos = m_clips.back();
m_hClipRgn = CreateRectRgn(clip_pos.left() - ptView.x, clip_pos.top() - ptView.y, clip_pos.right() - ptView.x, clip_pos.bottom() - ptView.y);
SelectClipRgn(hdc, m_hClipRgn);
}
}
void litehtml::win32_container::release_clip(HDC hdc)
{
SelectClipRgn(hdc, NULL);
if(m_hClipRgn)
{
DeleteObject(m_hClipRgn);
m_hClipRgn = NULL;
}
void litehtml::win32_container::release_clip(HDC hdc) {
SelectClipRgn(hdc, NULL);
if (m_hClipRgn) {
DeleteObject(m_hClipRgn);
m_hClipRgn = NULL;
}
}

View file

@ -1,65 +1,56 @@
#pragma once
#include <Windows.h>
namespace litehtml
{
class win32_container : public document_container
{
public:
typedef std::map<std::wstring, litehtml::uint_ptr> images_map;
namespace litehtml {
class win32_container : public document_container {
public:
typedef std::map<std::wstring, litehtml::uint_ptr> images_map;
protected:
protected:
images_map m_images;
litehtml::position::vector m_clips;
HRGN m_hClipRgn;
images_map m_images;
litehtml::position::vector m_clips;
HRGN m_hClipRgn;
public:
win32_container();
virtual ~win32_container();
public:
win32_container();
virtual ~win32_container();
// litehtml::document_container members
virtual uint_ptr create_font(const wchar_t* faceName, int size, int weight, font_style italic, unsigned int decoration);
virtual void delete_font(uint_ptr hFont);
virtual int line_height(uint_ptr hdc, uint_ptr hFont);
virtual int get_text_base_line(uint_ptr hdc, uint_ptr hFont);
virtual int text_width(uint_ptr hdc, const wchar_t* text, uint_ptr hFont);
virtual void draw_text(uint_ptr hdc, const wchar_t* text, uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos);
virtual void fill_rect(uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius);
virtual uint_ptr get_temp_dc();
virtual void release_temp_dc(uint_ptr hdc);
virtual int pt_to_px(int pt);
virtual void draw_list_marker(uint_ptr hdc, const litehtml::list_marker& marker);
virtual void load_image(const wchar_t* src, const wchar_t* baseurl, bool redraw_on_ready);
virtual void get_image_size(const wchar_t* src, const wchar_t* baseurl, litehtml::size& sz);
virtual void draw_image(uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos);
virtual void draw_background(uint_ptr hdc, const wchar_t* image, const wchar_t* baseurl, const litehtml::position& draw_pos, const litehtml::css_position& bg_pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment);
// litehtml::document_container members
virtual uint_ptr create_font(const wchar_t* faceName, int size, int weight, font_style italic, unsigned int decoration);
virtual void delete_font(uint_ptr hFont);
virtual int line_height(uint_ptr hdc, uint_ptr hFont);
virtual int get_text_base_line(uint_ptr hdc, uint_ptr hFont);
virtual int text_width(uint_ptr hdc, const wchar_t* text, uint_ptr hFont);
virtual void draw_text(uint_ptr hdc, const wchar_t* text, uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos);
virtual void fill_rect(uint_ptr hdc, const litehtml::position& pos, const litehtml::web_color color, const litehtml::css_border_radius& radius);
virtual uint_ptr get_temp_dc();
virtual void release_temp_dc(uint_ptr hdc);
virtual int pt_to_px(int pt);
virtual void draw_list_marker(uint_ptr hdc, const litehtml::list_marker& marker);
virtual void load_image(const wchar_t* src, const wchar_t* baseurl, bool redraw_on_ready);
virtual void get_image_size(const wchar_t* src, const wchar_t* baseurl, litehtml::size& sz);
virtual void draw_image(uint_ptr hdc, const wchar_t* src, const wchar_t* baseurl, const litehtml::position& pos);
virtual void draw_background(uint_ptr hdc,
const wchar_t* image,
const wchar_t* baseurl,
const litehtml::position& draw_pos,
const litehtml::css_position& bg_pos,
litehtml::background_repeat repeat,
litehtml::background_attachment attachment);
virtual int get_default_font_size() const;
virtual wchar_t toupper(const wchar_t c);
virtual wchar_t tolower(const wchar_t c);
virtual void set_clip(const litehtml::position& pos, bool valid_x, bool valid_y);
virtual void del_clip();
virtual int get_default_font_size() const;
virtual wchar_t toupper(const wchar_t c);
virtual wchar_t tolower(const wchar_t c);
virtual void set_clip(const litehtml::position& pos, bool valid_x, bool valid_y);
virtual void del_clip();
protected:
void apply_clip(HDC hdc);
void release_clip(HDC hdc);
void clear_images();
virtual void make_url( LPCWSTR url, LPCWSTR basepath, std::wstring& out ) = 0;
virtual uint_ptr get_image(LPCWSTR url) = 0;
virtual void free_image(uint_ptr img) = 0;
virtual void get_client_rect(litehtml::position& client) = 0;
virtual void draw_ellipse(HDC hdc, int x, int y, int width, int height, const web_color& color, int line_width) = 0;
virtual void fill_ellipse(HDC hdc, int x, int y, int width, int height, const web_color& color) = 0;
virtual void fill_rect(HDC hdc, int x, int y, int width, int height, const web_color& color, const litehtml::css_border_radius& radius) = 0;
virtual void get_img_size(litehtml::uint_ptr img, litehtml::size& sz) = 0;
virtual void draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos) = 0;
virtual void draw_img_bg(HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment) = 0;
};
}
protected:
void apply_clip(HDC hdc);
void release_clip(HDC hdc);
void clear_images();
virtual void make_url(LPCWSTR url, LPCWSTR basepath, std::wstring& out) = 0;
virtual uint_ptr get_image(LPCWSTR url) = 0;
virtual void free_image(uint_ptr img) = 0;
virtual void get_client_rect(litehtml::position& client) = 0;
virtual void draw_ellipse(HDC hdc, int x, int y, int width, int height, const web_color& color, int line_width) = 0;
virtual void fill_ellipse(HDC hdc, int x, int y, int width, int height, const web_color& color) = 0;
virtual void fill_rect(HDC hdc, int x, int y, int width, int height, const web_color& color, const litehtml::css_border_radius& radius) = 0;
virtual void get_img_size(litehtml::uint_ptr img, litehtml::size& sz) = 0;
virtual void draw_img(HDC hdc, litehtml::uint_ptr img, const litehtml::position& pos) = 0;
virtual void draw_img_bg(HDC hdc, litehtml::uint_ptr img, const litehtml::position& draw_pos, const litehtml::position& pos, litehtml::background_repeat repeat, litehtml::background_attachment attachment) = 0;
};
} // namespace litehtml

View file

@ -1,10 +1,10 @@
#ifndef LITEHTML_H
#define LITEHTML_H
#include <litehtml/html.h>
#include <litehtml/document.h>
#include <litehtml/element.h>
#include <litehtml/html.h>
#include <litehtml/html_tag.h>
#include <litehtml/stylesheet.h>
#include <litehtml/element.h>
#endif // LITEHTML_H

View file

@ -1,35 +1,30 @@
#ifndef LH_ATTRIBUTES_H
#define LH_ATTRIBUTES_H
namespace litehtml
{
struct attr_color
{
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbAlpha;
attr_color()
{
rgbAlpha = 255;
rgbBlue = 0;
rgbGreen = 0;
rgbRed = 0;
}
};
namespace litehtml {
struct attr_color {
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbAlpha;
attr_color() {
rgbAlpha = 255;
rgbBlue = 0;
rgbGreen = 0;
rgbRed = 0;
}
};
struct attr_border
{
style_border border;
int width;
attr_color color;
struct attr_border {
style_border border;
int width;
attr_color color;
attr_border()
{
border = borderNone;
width = 0;
}
};
}
attr_border() {
border = borderNone;
width = 0;
}
};
} // namespace litehtml
#endif // LH_ATTRIBUTES_H

View file

@ -1,58 +1,56 @@
#ifndef LH_BACKGROUND_H
#define LH_BACKGROUND_H
#include "types.h"
#include "attributes.h"
#include "borders.h"
#include "css_length.h"
#include "css_position.h"
#include "types.h"
#include "web_color.h"
#include "borders.h"
namespace litehtml
{
class background
{
public:
tstring m_image;
tstring m_baseurl;
web_color m_color;
background_attachment m_attachment;
css_position m_position;
background_repeat m_repeat;
background_box m_clip;
background_box m_origin;
css_border_radius m_radius;
namespace litehtml {
class background {
public:
tstring m_image;
tstring m_baseurl;
web_color m_color;
background_attachment m_attachment;
css_position m_position;
background_repeat m_repeat;
background_box m_clip;
background_box m_origin;
css_border_radius m_radius;
public:
background();
background(const background& val);
~background() = default;
public:
background();
background(const background& val);
~background() = default;
background& operator=(const background& val);
};
background& operator=(const background& val);
};
class background_paint
{
public:
tstring image;
tstring baseurl;
background_attachment attachment;
background_repeat repeat;
web_color color;
position clip_box;
position origin_box;
position border_box;
border_radiuses border_radius;
size image_size;
int position_x;
int position_y;
bool is_root;
public:
background_paint();
background_paint(const background_paint& val);
background_paint& operator=(const background& val);
};
class background_paint {
public:
tstring image;
tstring baseurl;
background_attachment attachment;
background_repeat repeat;
web_color color;
position clip_box;
position origin_box;
position border_box;
border_radiuses border_radius;
size image_size;
int position_x;
int position_y;
bool is_root;
}
public:
background_paint();
background_paint(const background_paint& val);
background_paint& operator=(const background& val);
};
} // namespace litehtml
#endif // LH_BACKGROUND_H

View file

@ -4,302 +4,259 @@
#include "css_length.h"
#include "types.h"
namespace litehtml
{
struct css_border
{
css_length width;
border_style style;
web_color color;
namespace litehtml {
struct css_border {
css_length width;
border_style style;
web_color color;
css_border()
{
style = border_style_none;
}
css_border() { style = border_style_none; }
css_border(const css_border& val)
{
width = val.width;
style = val.style;
color = val.color;
}
css_border(const css_border& val) {
width = val.width;
style = val.style;
color = val.color;
}
css_border& operator=(const css_border& val)
{
width = val.width;
style = val.style;
color = val.color;
return *this;
}
};
css_border& operator=(const css_border& val) {
width = val.width;
style = val.style;
color = val.color;
return *this;
}
};
struct border
{
int width;
border_style style;
web_color color;
struct border {
int width;
border_style style;
web_color color;
border()
{
width = 0;
}
border(const border& val)
{
width = val.width;
style = val.style;
color = val.color;
}
border(const css_border& val)
{
width = (int) val.width.val();
style = val.style;
color = val.color;
}
border& operator=(const border& val)
{
width = val.width;
style = val.style;
color = val.color;
return *this;
}
border& operator=(const css_border& val)
{
width = (int) val.width.val();
style = val.style;
color = val.color;
return *this;
}
};
border() { width = 0; }
border(const border& val) {
width = val.width;
style = val.style;
color = val.color;
}
border(const css_border& val) {
width = (int)val.width.val();
style = val.style;
color = val.color;
}
border& operator=(const border& val) {
width = val.width;
style = val.style;
color = val.color;
return *this;
}
border& operator=(const css_border& val) {
width = (int)val.width.val();
style = val.style;
color = val.color;
return *this;
}
};
struct border_radiuses
{
int top_left_x;
int top_left_y;
struct border_radiuses {
int top_left_x;
int top_left_y;
int top_right_x;
int top_right_y;
int top_right_x;
int top_right_y;
int bottom_right_x;
int bottom_right_y;
int bottom_right_x;
int bottom_right_y;
int bottom_left_x;
int bottom_left_y;
int bottom_left_x;
int bottom_left_y;
border_radiuses()
{
top_left_x = 0;
top_left_y = 0;
top_right_x = 0;
top_right_y = 0;
bottom_right_x = 0;
bottom_right_y = 0;
bottom_left_x = 0;
bottom_left_y = 0;
}
border_radiuses(const border_radiuses& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
}
border_radiuses& operator = (const border_radiuses& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
return *this;
}
void operator += (const margins& mg)
{
top_left_x += mg.left;
top_left_y += mg.top;
top_right_x += mg.right;
top_right_y += mg.top;
bottom_right_x += mg.right;
bottom_right_y += mg.bottom;
bottom_left_x += mg.left;
bottom_left_y += mg.bottom;
fix_values();
}
void operator -= (const margins& mg)
{
top_left_x -= mg.left;
top_left_y -= mg.top;
top_right_x -= mg.right;
top_right_y -= mg.top;
bottom_right_x -= mg.right;
bottom_right_y -= mg.bottom;
bottom_left_x -= mg.left;
bottom_left_y -= mg.bottom;
fix_values();
}
void fix_values()
{
if (top_left_x < 0) top_left_x = 0;
if (top_left_y < 0) top_left_y = 0;
if (top_right_x < 0) top_right_x = 0;
if (top_right_y < 0) top_right_y = 0;
if (bottom_right_x < 0) bottom_right_x = 0;
if (bottom_right_y < 0) bottom_right_y = 0;
if (bottom_left_x < 0) bottom_left_x = 0;
if (bottom_left_y < 0) bottom_left_y = 0;
}
};
border_radiuses() {
top_left_x = 0;
top_left_y = 0;
top_right_x = 0;
top_right_y = 0;
bottom_right_x = 0;
bottom_right_y = 0;
bottom_left_x = 0;
bottom_left_y = 0;
}
border_radiuses(const border_radiuses& val) {
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
}
border_radiuses& operator=(const border_radiuses& val) {
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
return *this;
}
void operator+=(const margins& mg) {
top_left_x += mg.left;
top_left_y += mg.top;
top_right_x += mg.right;
top_right_y += mg.top;
bottom_right_x += mg.right;
bottom_right_y += mg.bottom;
bottom_left_x += mg.left;
bottom_left_y += mg.bottom;
fix_values();
}
void operator-=(const margins& mg) {
top_left_x -= mg.left;
top_left_y -= mg.top;
top_right_x -= mg.right;
top_right_y -= mg.top;
bottom_right_x -= mg.right;
bottom_right_y -= mg.bottom;
bottom_left_x -= mg.left;
bottom_left_y -= mg.bottom;
fix_values();
}
void fix_values() {
if (top_left_x < 0) top_left_x = 0;
if (top_left_y < 0) top_left_y = 0;
if (top_right_x < 0) top_right_x = 0;
if (top_right_y < 0) top_right_y = 0;
if (bottom_right_x < 0) bottom_right_x = 0;
if (bottom_right_y < 0) bottom_right_y = 0;
if (bottom_left_x < 0) bottom_left_x = 0;
if (bottom_left_y < 0) bottom_left_y = 0;
}
};
struct css_border_radius
{
css_length top_left_x;
css_length top_left_y;
struct css_border_radius {
css_length top_left_x;
css_length top_left_y;
css_length top_right_x;
css_length top_right_y;
css_length top_right_x;
css_length top_right_y;
css_length bottom_right_x;
css_length bottom_right_y;
css_length bottom_right_x;
css_length bottom_right_y;
css_length bottom_left_x;
css_length bottom_left_y;
css_length bottom_left_x;
css_length bottom_left_y;
css_border_radius()
{
css_border_radius() {}
}
css_border_radius(const css_border_radius& val) {
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
}
css_border_radius(const css_border_radius& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
}
css_border_radius& operator=(const css_border_radius& val) {
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
return *this;
}
border_radiuses calc_percents(int width, int height) {
border_radiuses ret;
ret.bottom_left_x = bottom_left_x.calc_percent(width);
ret.bottom_left_y = bottom_left_y.calc_percent(height);
ret.top_left_x = top_left_x.calc_percent(width);
ret.top_left_y = top_left_y.calc_percent(height);
ret.top_right_x = top_right_x.calc_percent(width);
ret.top_right_y = top_right_y.calc_percent(height);
ret.bottom_right_x = bottom_right_x.calc_percent(width);
ret.bottom_right_y = bottom_right_y.calc_percent(height);
return ret;
}
};
css_border_radius& operator=(const css_border_radius& val)
{
top_left_x = val.top_left_x;
top_left_y = val.top_left_y;
top_right_x = val.top_right_x;
top_right_y = val.top_right_y;
bottom_left_x = val.bottom_left_x;
bottom_left_y = val.bottom_left_y;
bottom_right_x = val.bottom_right_x;
bottom_right_y = val.bottom_right_y;
return *this;
}
border_radiuses calc_percents(int width, int height)
{
border_radiuses ret;
ret.bottom_left_x = bottom_left_x.calc_percent(width);
ret.bottom_left_y = bottom_left_y.calc_percent(height);
ret.top_left_x = top_left_x.calc_percent(width);
ret.top_left_y = top_left_y.calc_percent(height);
ret.top_right_x = top_right_x.calc_percent(width);
ret.top_right_y = top_right_y.calc_percent(height);
ret.bottom_right_x = bottom_right_x.calc_percent(width);
ret.bottom_right_y = bottom_right_y.calc_percent(height);
return ret;
}
};
struct css_borders {
css_border left;
css_border top;
css_border right;
css_border bottom;
css_border_radius radius;
struct css_borders
{
css_border left;
css_border top;
css_border right;
css_border bottom;
css_border_radius radius;
css_borders() = default;
css_borders() = default;
bool is_visible() const { return left.width.val() != 0 || right.width.val() != 0 || top.width.val() != 0 || bottom.width.val() != 0; }
bool is_visible() const
{
return left.width.val() != 0 || right.width.val() != 0 || top.width.val() != 0 || bottom.width.val() != 0;
}
css_borders(const css_borders& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
}
css_borders(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
}
css_borders& operator=(const css_borders& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
return *this;
}
};
css_borders& operator=(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
return *this;
}
};
struct borders {
border left;
border top;
border right;
border bottom;
border_radiuses radius;
struct borders
{
border left;
border top;
border right;
border bottom;
border_radiuses radius;
borders() = default;
borders() = default;
borders(const borders& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
}
borders(const borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
}
borders(const css_borders& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
}
borders(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
}
bool is_visible() const { return left.width != 0 || right.width != 0 || top.width != 0 || bottom.width != 0; }
bool is_visible() const
{
return left.width != 0 || right.width != 0 || top.width != 0 || bottom.width != 0;
}
borders& operator=(const borders& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
return *this;
}
borders& operator=(const borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
radius = val.radius;
return *this;
}
borders& operator=(const css_borders& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
return *this;
}
};
}
borders& operator=(const css_borders& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
return *this;
}
};
} // namespace litehtml
#endif // LH_BORDERS_H

View file

@ -1,120 +1,111 @@
#ifndef LH_BOX_H
#define LH_BOX_H
namespace litehtml
{
class html_tag;
namespace litehtml {
class html_tag;
enum box_type
{
box_block,
box_line
};
enum box_type { box_block, box_line };
class box
{
public:
typedef std::unique_ptr<litehtml::box> ptr;
typedef std::vector< box::ptr > vector;
protected:
int m_box_top;
int m_box_left;
int m_box_right;
public:
box(int top, int left, int right)
{
m_box_top = top;
m_box_left = left;
m_box_right = right;
}
virtual ~box() = default;
class box {
public:
typedef std::unique_ptr<litehtml::box> ptr;
typedef std::vector<box::ptr> vector;
int bottom() const { return m_box_top + height(); }
int top() const { return m_box_top; }
int right() const { return m_box_left + width(); }
int left() const { return m_box_left; }
protected:
int m_box_top;
int m_box_left;
int m_box_right;
virtual litehtml::box_type get_type() const = 0;
virtual int height() const = 0;
virtual int width() const = 0;
virtual void add_element(const element::ptr &el) = 0;
virtual bool can_hold(const element::ptr &el, white_space ws) const = 0;
virtual void finish(bool last_box = false) = 0;
virtual bool is_empty() const = 0;
virtual int baseline() const = 0;
virtual void get_elements(elements_vector& els) = 0;
virtual int top_margin() const = 0;
virtual int bottom_margin() const = 0;
virtual void y_shift(int shift) = 0;
virtual void new_width(int left, int right, elements_vector& els) = 0;
};
public:
box(int top, int left, int right) {
m_box_top = top;
m_box_left = left;
m_box_right = right;
}
virtual ~box() = default;
//////////////////////////////////////////////////////////////////////////
int bottom() const { return m_box_top + height(); }
int top() const { return m_box_top; }
int right() const { return m_box_left + width(); }
int left() const { return m_box_left; }
class block_box : public box
{
element::ptr m_element;
public:
block_box(int top, int left, int right) : box(top, left, right)
{
m_element = nullptr;
}
virtual litehtml::box_type get_type() const = 0;
virtual int height() const = 0;
virtual int width() const = 0;
virtual void add_element(const element::ptr& el) = 0;
virtual bool can_hold(const element::ptr& el, white_space ws) const = 0;
virtual void finish(bool last_box = false) = 0;
virtual bool is_empty() const = 0;
virtual int baseline() const = 0;
virtual void get_elements(elements_vector& els) = 0;
virtual int top_margin() const = 0;
virtual int bottom_margin() const = 0;
virtual void y_shift(int shift) = 0;
virtual void new_width(int left, int right, elements_vector& els) = 0;
};
litehtml::box_type get_type() const override;
int height() const override;
int width() const override;
void add_element(const element::ptr &el) override;
bool can_hold(const element::ptr &el, white_space ws) const override;
void finish(bool last_box = false) override;
bool is_empty() const override;
int baseline() const override;
void get_elements(elements_vector& els) override;
int top_margin() const override;
int bottom_margin() const override;
void y_shift(int shift) override;
void new_width(int left, int right, elements_vector& els) override;
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
class block_box : public box {
element::ptr m_element;
class line_box : public box
{
elements_vector m_items;
int m_height;
int m_width;
int m_line_height;
font_metrics m_font_metrics;
int m_baseline;
text_align m_text_align;
public:
line_box(int top, int left, int right, int line_height, font_metrics& fm, text_align align) : box(top, left, right)
{
m_height = 0;
m_width = 0;
m_font_metrics = fm;
m_line_height = line_height;
m_baseline = 0;
m_text_align = align;
}
public:
block_box(int top, int left, int right) : box(top, left, right) { m_element = nullptr; }
litehtml::box_type get_type() const override;
int height() const override;
int width() const override;
void add_element(const element::ptr &el) override;
bool can_hold(const element::ptr &el, white_space ws) const override;
void finish(bool last_box = false) override;
bool is_empty() const override;
int baseline() const override;
void get_elements(elements_vector& els) override;
int top_margin() const override;
int bottom_margin() const override;
void y_shift(int shift) override;
void new_width(int left, int right, elements_vector& els) override;
litehtml::box_type get_type() const override;
int height() const override;
int width() const override;
void add_element(const element::ptr& el) override;
bool can_hold(const element::ptr& el, white_space ws) const override;
void finish(bool last_box = false) override;
bool is_empty() const override;
int baseline() const override;
void get_elements(elements_vector& els) override;
int top_margin() const override;
int bottom_margin() const override;
void y_shift(int shift) override;
void new_width(int left, int right, elements_vector& els) override;
};
private:
bool have_last_space() const;
bool is_break_only() const;
};
}
//////////////////////////////////////////////////////////////////////////
class line_box : public box {
elements_vector m_items;
int m_height;
int m_width;
int m_line_height;
font_metrics m_font_metrics;
int m_baseline;
text_align m_text_align;
public:
line_box(int top, int left, int right, int line_height, font_metrics& fm, text_align align) : box(top, left, right) {
m_height = 0;
m_width = 0;
m_font_metrics = fm;
m_line_height = line_height;
m_baseline = 0;
m_text_align = align;
}
litehtml::box_type get_type() const override;
int height() const override;
int width() const override;
void add_element(const element::ptr& el) override;
bool can_hold(const element::ptr& el, white_space ws) const override;
void finish(bool last_box = false) override;
bool is_empty() const override;
int baseline() const override;
void get_elements(elements_vector& els) override;
int top_margin() const override;
int bottom_margin() const override;
void y_shift(int shift) override;
void new_width(int left, int right, elements_vector& els) override;
private:
bool have_last_space() const;
bool is_break_only() const;
};
} // namespace litehtml
#endif // LH_BOX_H

View file

@ -46,6 +46,6 @@ bool is_url_reserved_codepoint(litehtml::tchar_t c);
// https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
bool is_url_scheme_codepoint(litehtml::tchar_t c);
} // namespace litehtml
} // namespace litehtml
#endif // LITEHTML_CODEPOINT_H__
#endif // LITEHTML_CODEPOINT_H__

View file

@ -3,18 +3,14 @@
#include "stylesheet.h"
namespace litehtml
{
class context
{
litehtml::css m_master_css;
public:
void load_master_stylesheet(const tchar_t* str);
litehtml::css& master_css()
{
return m_master_css;
}
};
}
namespace litehtml {
class context {
litehtml::css m_master_css;
public:
void load_master_stylesheet(const tchar_t* str);
litehtml::css& master_css() { return m_master_css; }
};
} // namespace litehtml
#endif // LH_CONTEXT_H

View file

@ -3,133 +3,107 @@
#include "types.h"
namespace litehtml
{
class css_length
{
union
{
float m_value;
int m_predef;
};
css_units m_units;
bool m_is_predefined;
public:
css_length();
css_length(const css_length& val);
namespace litehtml {
class css_length {
union {
float m_value;
int m_predef;
};
css_units m_units;
bool m_is_predefined;
css_length& operator=(const css_length& val);
css_length& operator=(float val);
bool is_predefined() const;
void predef(int val);
int predef() const;
void set_value(float val, css_units units);
float val() const;
css_units units() const;
int calc_percent(int width) const;
void fromString(const tstring& str, const tstring& predefs = _t(""), int defValue = 0);
};
public:
css_length();
css_length(const css_length& val);
// css_length inlines
css_length& operator=(const css_length& val);
css_length& operator=(float val);
bool is_predefined() const;
void predef(int val);
int predef() const;
void set_value(float val, css_units units);
float val() const;
css_units units() const;
int calc_percent(int width) const;
void fromString(const tstring& str, const tstring& predefs = _t(""), int defValue = 0);
};
inline css_length::css_length()
{
m_value = 0;
m_predef = 0;
m_units = css_units_none;
m_is_predefined = false;
}
// css_length inlines
inline css_length::css_length(const css_length& val)
{
if(val.is_predefined())
{
m_predef = val.m_predef;
} else
{
m_value = val.m_value;
}
m_units = val.m_units;
m_is_predefined = val.m_is_predefined;
}
inline css_length& css_length::operator=(const css_length& val)
{
if(val.is_predefined())
{
m_predef = val.m_predef;
} else
{
m_value = val.m_value;
}
m_units = val.m_units;
m_is_predefined = val.m_is_predefined;
return *this;
}
inline css_length& css_length::operator=(float val)
{
m_value = val;
m_units = css_units_px;
m_is_predefined = false;
return *this;
}
inline bool css_length::is_predefined() const
{
return m_is_predefined;
}
inline void css_length::predef(int val)
{
m_predef = val;
m_is_predefined = true;
}
inline int css_length::predef() const
{
if(m_is_predefined)
{
return m_predef;
}
return 0;
}
inline void css_length::set_value(float val, css_units units)
{
m_value = val;
m_is_predefined = false;
m_units = units;
}
inline float css_length::val() const
{
if(!m_is_predefined)
{
return m_value;
}
return 0;
}
inline css_units css_length::units() const
{
return m_units;
}
inline int css_length::calc_percent(int width) const
{
if(!is_predefined())
{
if(units() == css_units_percentage)
{
return (int) ((double) width * (double) m_value / 100.0);
} else
{
return (int) val();
}
}
return 0;
}
inline css_length::css_length() {
m_value = 0;
m_predef = 0;
m_units = css_units_none;
m_is_predefined = false;
}
inline css_length::css_length(const css_length& val) {
if (val.is_predefined()) {
m_predef = val.m_predef;
} else {
m_value = val.m_value;
}
m_units = val.m_units;
m_is_predefined = val.m_is_predefined;
}
inline css_length& css_length::operator=(const css_length& val) {
if (val.is_predefined()) {
m_predef = val.m_predef;
} else {
m_value = val.m_value;
}
m_units = val.m_units;
m_is_predefined = val.m_is_predefined;
return *this;
}
inline css_length& css_length::operator=(float val) {
m_value = val;
m_units = css_units_px;
m_is_predefined = false;
return *this;
}
inline bool css_length::is_predefined() const { return m_is_predefined; }
inline void css_length::predef(int val) {
m_predef = val;
m_is_predefined = true;
}
inline int css_length::predef() const {
if (m_is_predefined) {
return m_predef;
}
return 0;
}
inline void css_length::set_value(float val, css_units units) {
m_value = val;
m_is_predefined = false;
m_units = units;
}
inline float css_length::val() const {
if (!m_is_predefined) {
return m_value;
}
return 0;
}
inline css_units css_length::units() const { return m_units; }
inline int css_length::calc_percent(int width) const {
if (!is_predefined()) {
if (units() == css_units_percentage) {
return (int)((double)width * (double)m_value / 100.0);
} else {
return (int)val();
}
}
return 0;
}
} // namespace litehtml
#endif // LH_CSS_LENGTH_H

View file

@ -3,34 +3,30 @@
#include "css_length.h"
namespace litehtml
{
struct css_margins
{
css_length left;
css_length right;
css_length top;
css_length bottom;
namespace litehtml {
struct css_margins {
css_length left;
css_length right;
css_length top;
css_length bottom;
css_margins() = default;
css_margins() = default;
css_margins(const css_margins& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
}
css_margins(const css_margins& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
}
css_margins& operator=(const css_margins& val)
{
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
return *this;
}
};
}
css_margins& operator=(const css_margins& val) {
left = val.left;
right = val.right;
top = val.top;
bottom = val.bottom;
return *this;
}
};
} // namespace litehtml
#endif // LH_CSS_MARGINS_H

View file

@ -3,34 +3,30 @@
#include "css_length.h"
namespace litehtml
{
struct css_offsets
{
css_length left;
css_length top;
css_length right;
css_length bottom;
namespace litehtml {
struct css_offsets {
css_length left;
css_length top;
css_length right;
css_length bottom;
css_offsets() = default;
css_offsets() = default;
css_offsets(const css_offsets& val)
{
left = val.left;
top = val.top;
right = val.right;
bottom = val.bottom;
}
css_offsets(const css_offsets& val) {
left = val.left;
top = val.top;
right = val.right;
bottom = val.bottom;
}
css_offsets& operator=(const css_offsets& val)
{
left = val.left;
top = val.top;
right = val.right;
bottom = val.bottom;
return *this;
}
};
}
css_offsets& operator=(const css_offsets& val) {
left = val.left;
top = val.top;
right = val.right;
bottom = val.bottom;
return *this;
}
};
} // namespace litehtml
#endif // LH_CSS_OFFSETS_H

View file

@ -3,34 +3,30 @@
#include "css_length.h"
namespace litehtml
{
struct css_position
{
css_length x;
css_length y;
css_length width;
css_length height;
namespace litehtml {
struct css_position {
css_length x;
css_length y;
css_length width;
css_length height;
css_position() = default;
css_position() = default;
css_position(const css_position& val)
{
x = val.x;
y = val.y;
width = val.width;
height = val.height;
}
css_position(const css_position& val) {
x = val.x;
y = val.y;
width = val.width;
height = val.height;
}
css_position& operator=(const css_position& val)
{
x = val.x;
y = val.y;
width = val.width;
height = val.height;
return *this;
}
};
}
css_position& operator=(const css_position& val) {
x = val.x;
y = val.y;
width = val.width;
height = val.height;
return *this;
}
};
} // namespace litehtml
#endif // LH_CSS_POSITION_H

View file

@ -1,276 +1,220 @@
#ifndef LH_CSS_SELECTOR_H
#define LH_CSS_SELECTOR_H
#include "style.h"
#include "media_query.h"
#include "style.h"
namespace litehtml
{
//////////////////////////////////////////////////////////////////////////
namespace litehtml {
//////////////////////////////////////////////////////////////////////////
struct selector_specificity
{
int a;
int b;
int c;
int d;
struct selector_specificity {
int a;
int b;
int c;
int d;
explicit selector_specificity(int va = 0, int vb = 0, int vc = 0, int vd = 0)
{
a = va;
b = vb;
c = vc;
d = vd;
}
explicit selector_specificity(int va = 0, int vb = 0, int vc = 0, int vd = 0) {
a = va;
b = vb;
c = vc;
d = vd;
}
void operator += (const selector_specificity& val)
{
a += val.a;
b += val.b;
c += val.c;
d += val.d;
}
void operator+=(const selector_specificity& val) {
a += val.a;
b += val.b;
c += val.c;
d += val.d;
}
bool operator==(const selector_specificity& val) const
{
if(a == val.a && b == val.b && c == val.c && d == val.d)
{
return true;
}
return false;
}
bool operator==(const selector_specificity& val) const {
if (a == val.a && b == val.b && c == val.c && d == val.d) {
return true;
}
return false;
}
bool operator!=(const selector_specificity& val) const
{
if(a != val.a || b != val.b || c != val.c || d != val.d)
{
return true;
}
return false;
}
bool operator!=(const selector_specificity& val) const {
if (a != val.a || b != val.b || c != val.c || d != val.d) {
return true;
}
return false;
}
bool operator > (const selector_specificity& val) const
{
if(a > val.a)
{
return true;
} else if(a < val.a)
{
return false;
} else
{
if(b > val.b)
{
return true;
} else if(b < val.b)
{
return false;
} else
{
if(c > val.c)
{
return true;
} else if(c < val.c)
{
return false;
} else
{
if(d > val.d)
{
return true;
} else if(d < val.d)
{
return false;
}
}
}
}
return false;
}
bool operator>(const selector_specificity& val) const {
if (a > val.a) {
return true;
} else if (a < val.a) {
return false;
} else {
if (b > val.b) {
return true;
} else if (b < val.b) {
return false;
} else {
if (c > val.c) {
return true;
} else if (c < val.c) {
return false;
} else {
if (d > val.d) {
return true;
} else if (d < val.d) {
return false;
}
}
}
}
return false;
}
bool operator >= (const selector_specificity& val) const
{
if((*this) == val) return true;
if((*this) > val) return true;
return false;
}
bool operator>=(const selector_specificity& val) const {
if ((*this) == val) return true;
if ((*this) > val) return true;
return false;
}
bool operator <= (const selector_specificity& val) const
{
if((*this) > val)
{
return false;
}
return true;
}
bool operator<=(const selector_specificity& val) const {
if ((*this) > val) {
return false;
}
return true;
}
bool operator < (const selector_specificity& val) const
{
if((*this) <= val && (*this) != val)
{
return true;
}
return false;
}
bool operator<(const selector_specificity& val) const {
if ((*this) <= val && (*this) != val) {
return true;
}
return false;
}
};
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
enum attr_select_condition {
select_exists,
select_equal,
select_contain_str,
select_start_str,
select_end_str,
select_pseudo_class,
select_pseudo_element,
};
enum attr_select_condition
{
select_exists,
select_equal,
select_contain_str,
select_start_str,
select_end_str,
select_pseudo_class,
select_pseudo_element,
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
struct css_attribute_selector {
typedef std::vector<css_attribute_selector> vector;
struct css_attribute_selector
{
typedef std::vector<css_attribute_selector> vector;
tstring attribute;
tstring val;
string_vector class_val;
attr_select_condition condition;
tstring attribute;
tstring val;
string_vector class_val;
attr_select_condition condition;
css_attribute_selector() { condition = select_exists; }
};
css_attribute_selector()
{
condition = select_exists;
}
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
class css_element_selector {
public:
tstring m_tag;
css_attribute_selector::vector m_attrs;
class css_element_selector
{
public:
tstring m_tag;
css_attribute_selector::vector m_attrs;
public:
public:
void parse(const tstring& txt);
};
void parse(const tstring& txt);
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
enum css_combinator { combinator_descendant, combinator_child, combinator_adjacent_sibling, combinator_general_sibling };
enum css_combinator
{
combinator_descendant,
combinator_child,
combinator_adjacent_sibling,
combinator_general_sibling
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
class css_selector {
public:
typedef std::shared_ptr<css_selector> ptr;
typedef std::vector<css_selector::ptr> vector;
class css_selector
{
public:
typedef std::shared_ptr<css_selector> ptr;
typedef std::vector<css_selector::ptr> vector;
public:
selector_specificity m_specificity;
css_element_selector m_right;
css_selector::ptr m_left;
css_combinator m_combinator;
style::ptr m_style;
int m_order;
media_query_list::ptr m_media_query;
public:
explicit css_selector(const media_query_list::ptr& media)
{
m_media_query = media;
m_combinator = combinator_descendant;
m_order = 0;
}
public:
selector_specificity m_specificity;
css_element_selector m_right;
css_selector::ptr m_left;
css_combinator m_combinator;
style::ptr m_style;
int m_order;
media_query_list::ptr m_media_query;
~css_selector() = default;
public:
explicit css_selector(const media_query_list::ptr& media) {
m_media_query = media;
m_combinator = combinator_descendant;
m_order = 0;
}
css_selector(const css_selector& val)
{
m_right = val.m_right;
if(val.m_left)
{
m_left = std::make_shared<css_selector>(*val.m_left);
} else
{
m_left = nullptr;
}
m_combinator = val.m_combinator;
m_specificity = val.m_specificity;
m_order = val.m_order;
m_media_query = val.m_media_query;
}
~css_selector() = default;
bool parse(const tstring& text);
void calc_specificity();
bool is_media_valid() const;
void add_media_to_doc(document* doc) const;
};
css_selector(const css_selector& val) {
m_right = val.m_right;
if (val.m_left) {
m_left = std::make_shared<css_selector>(*val.m_left);
} else {
m_left = nullptr;
}
m_combinator = val.m_combinator;
m_specificity = val.m_specificity;
m_order = val.m_order;
m_media_query = val.m_media_query;
}
inline bool css_selector::is_media_valid() const
{
if(!m_media_query)
{
return true;
}
return m_media_query->is_used();
}
bool parse(const tstring& text);
void calc_specificity();
bool is_media_valid() const;
void add_media_to_doc(document* doc) const;
};
//////////////////////////////////////////////////////////////////////////
inline bool operator > (const css_selector& v1, const css_selector& v2)
{
if(v1.m_specificity == v2.m_specificity)
{
return (v1.m_order > v2.m_order);
}
return (v1.m_specificity > v2.m_specificity);
}
inline bool operator < (const css_selector& v1, const css_selector& v2)
{
if(v1.m_specificity == v2.m_specificity)
{
return (v1.m_order < v2.m_order);
}
return (v1.m_specificity < v2.m_specificity);
}
inline bool operator >(const css_selector::ptr& v1, const css_selector::ptr& v2)
{
return (*v1 > *v2);
}
inline bool operator < (const css_selector::ptr& v1, const css_selector::ptr& v2)
{
return (*v1 < *v2);
}
//////////////////////////////////////////////////////////////////////////
class used_selector
{
public:
typedef std::unique_ptr<used_selector> ptr;
typedef std::vector<used_selector::ptr> vector;
css_selector::ptr m_selector;
bool m_used;
used_selector(const css_selector::ptr& selector, bool used)
{
m_used = used;
m_selector = selector;
}
};
inline bool css_selector::is_media_valid() const {
if (!m_media_query) {
return true;
}
return m_media_query->is_used();
}
//////////////////////////////////////////////////////////////////////////
inline bool operator>(const css_selector& v1, const css_selector& v2) {
if (v1.m_specificity == v2.m_specificity) {
return (v1.m_order > v2.m_order);
}
return (v1.m_specificity > v2.m_specificity);
}
inline bool operator<(const css_selector& v1, const css_selector& v2) {
if (v1.m_specificity == v2.m_specificity) {
return (v1.m_order < v2.m_order);
}
return (v1.m_specificity < v2.m_specificity);
}
inline bool operator>(const css_selector::ptr& v1, const css_selector::ptr& v2) { return (*v1 > *v2); }
inline bool operator<(const css_selector::ptr& v1, const css_selector::ptr& v2) { return (*v1 < *v2); }
//////////////////////////////////////////////////////////////////////////
class used_selector {
public:
typedef std::unique_ptr<used_selector> ptr;
typedef std::vector<used_selector::ptr> vector;
css_selector::ptr m_selector;
bool m_used;
used_selector(const css_selector::ptr& selector, bool used) {
m_used = used;
m_selector = selector;
}
};
} // namespace litehtml
#endif // LH_CSS_SELECTOR_H

View file

@ -1,117 +1,105 @@
#ifndef LH_DOCUMENT_H
#define LH_DOCUMENT_H
#include "context.h"
#include "style.h"
#include "types.h"
#include "context.h"
namespace litehtml
{
struct css_text
{
typedef std::vector<css_text> vector;
namespace litehtml {
struct css_text {
typedef std::vector<css_text> vector;
tstring text;
tstring baseurl;
tstring media;
tstring text;
tstring baseurl;
tstring media;
css_text() = default;
css_text() = default;
css_text(const tchar_t* txt, const tchar_t* url, const tchar_t* media_str)
{
text = txt ? txt : _t("");
baseurl = url ? url : _t("");
media = media_str ? media_str : _t("");
}
css_text(const tchar_t* txt, const tchar_t* url, const tchar_t* media_str) {
text = txt ? txt : _t("");
baseurl = url ? url : _t("");
media = media_str ? media_str : _t("");
}
css_text(const css_text& val)
{
text = val.text;
baseurl = val.baseurl;
media = val.media;
}
};
css_text(const css_text& val) {
text = val.text;
baseurl = val.baseurl;
media = val.media;
}
};
class html_tag;
class html_tag;
class document : public std::enable_shared_from_this<document>
{
public:
typedef std::shared_ptr<document> ptr;
typedef std::weak_ptr<document> weak_ptr;
private:
std::shared_ptr<element> m_root;
document_container* m_container;
fonts_map m_fonts;
css_text::vector m_css;
litehtml::css m_styles;
litehtml::web_color m_def_color;
litehtml::context* m_context;
litehtml::size m_size;
position::vector m_fixed_boxes;
media_query_list::vector m_media_lists;
element::ptr m_over_element;
elements_vector m_tabular_elements;
media_features m_media;
tstring m_lang;
tstring m_culture;
public:
document(litehtml::document_container* objContainer, litehtml::context* ctx);
virtual ~document();
class document : public std::enable_shared_from_this<document> {
public:
typedef std::shared_ptr<document> ptr;
typedef std::weak_ptr<document> weak_ptr;
litehtml::document_container* container() { return m_container; }
uint_ptr get_font(const tchar_t* name, int size, const tchar_t* weight, const tchar_t* style, const tchar_t* decoration, font_metrics* fm);
int render(int max_width, render_type rt = render_all);
void draw(uint_ptr hdc, int x, int y, const position* clip);
web_color get_def_color() { return m_def_color; }
int cvt_units(const tchar_t* str, int fontSize, bool* is_percent = nullptr) const;
int cvt_units(css_length& val, int fontSize, int size = 0) const;
int width() const;
int height() const;
void add_stylesheet(const tchar_t* str, const tchar_t* baseurl, const tchar_t* media);
bool on_mouse_over(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
bool on_lbutton_down(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
bool on_lbutton_up(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
bool on_mouse_leave(position::vector& redraw_boxes);
litehtml::element::ptr create_element(const tchar_t* tag_name, const string_map& attributes);
element::ptr root();
void get_fixed_boxes(position::vector& fixed_boxes);
void add_fixed_box(const position& pos);
void add_media_list(const media_query_list::ptr& list);
bool media_changed();
bool lang_changed();
bool match_lang(const tstring & lang);
void add_tabular(const element::ptr& el);
element::const_ptr get_over_element() const { return m_over_element; }
private:
std::shared_ptr<element> m_root;
document_container* m_container;
fonts_map m_fonts;
css_text::vector m_css;
litehtml::css m_styles;
litehtml::web_color m_def_color;
litehtml::context* m_context;
litehtml::size m_size;
position::vector m_fixed_boxes;
media_query_list::vector m_media_lists;
element::ptr m_over_element;
elements_vector m_tabular_elements;
media_features m_media;
tstring m_lang;
tstring m_culture;
void append_children_from_string(element& parent, const tchar_t* str);
void append_children_from_utf8(element& parent, const char* str);
public:
document(litehtml::document_container* objContainer, litehtml::context* ctx);
virtual ~document();
static litehtml::document::ptr createFromString(const tchar_t* str, litehtml::document_container* objPainter, litehtml::context* ctx, litehtml::css* user_styles = nullptr);
static litehtml::document::ptr createFromUTF8(const char* str, litehtml::document_container* objPainter, litehtml::context* ctx, litehtml::css* user_styles = nullptr);
litehtml::document_container* container() { return m_container; }
uint_ptr get_font(const tchar_t* name, int size, const tchar_t* weight, const tchar_t* style, const tchar_t* decoration, font_metrics* fm);
int render(int max_width, render_type rt = render_all);
void draw(uint_ptr hdc, int x, int y, const position* clip);
web_color get_def_color() { return m_def_color; }
int cvt_units(const tchar_t* str, int fontSize, bool* is_percent = nullptr) const;
int cvt_units(css_length& val, int fontSize, int size = 0) const;
int width() const;
int height() const;
void add_stylesheet(const tchar_t* str, const tchar_t* baseurl, const tchar_t* media);
bool on_mouse_over(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
bool on_lbutton_down(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
bool on_lbutton_up(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
bool on_mouse_leave(position::vector& redraw_boxes);
litehtml::element::ptr create_element(const tchar_t* tag_name, const string_map& attributes);
element::ptr root();
void get_fixed_boxes(position::vector& fixed_boxes);
void add_fixed_box(const position& pos);
void add_media_list(const media_query_list::ptr& list);
bool media_changed();
bool lang_changed();
bool match_lang(const tstring& lang);
void add_tabular(const element::ptr& el);
element::const_ptr get_over_element() const { return m_over_element; }
private:
litehtml::uint_ptr add_font(const tchar_t* name, int size, const tchar_t* weight, const tchar_t* style, const tchar_t* decoration, font_metrics* fm);
void append_children_from_string(element& parent, const tchar_t* str);
void append_children_from_utf8(element& parent, const char* str);
void create_node(void* gnode, elements_vector& elements, bool parseTextNode);
bool update_media_lists(const media_features& features);
void fix_tables_layout();
void fix_table_children(element::ptr& el_ptr, style_display disp, const tchar_t* disp_str);
void fix_table_parent(element::ptr& el_ptr, style_display disp, const tchar_t* disp_str);
};
static litehtml::document::ptr createFromString(const tchar_t* str, litehtml::document_container* objPainter, litehtml::context* ctx, litehtml::css* user_styles = nullptr);
static litehtml::document::ptr createFromUTF8(const char* str, litehtml::document_container* objPainter, litehtml::context* ctx, litehtml::css* user_styles = nullptr);
inline element::ptr document::root()
{
return m_root;
}
inline void document::add_tabular(const element::ptr& el)
{
m_tabular_elements.push_back(el);
}
inline bool document::match_lang(const tstring & lang)
{
return lang == m_lang || lang == m_culture;
}
}
private:
litehtml::uint_ptr add_font(const tchar_t* name, int size, const tchar_t* weight, const tchar_t* style, const tchar_t* decoration, font_metrics* fm);
void create_node(void* gnode, elements_vector& elements, bool parseTextNode);
bool update_media_lists(const media_features& features);
void fix_tables_layout();
void fix_table_children(element::ptr& el_ptr, style_display disp, const tchar_t* disp_str);
void fix_table_parent(element::ptr& el_ptr, style_display disp, const tchar_t* disp_str);
};
inline element::ptr document::root() { return m_root; }
inline void document::add_tabular(const element::ptr& el) { m_tabular_elements.push_back(el); }
inline bool document::match_lang(const tstring& lang) { return lang == m_lang || lang == m_culture; }
} // namespace litehtml
#endif // LH_DOCUMENT_H

View file

@ -3,16 +3,14 @@
#include "html_tag.h"
namespace litehtml
{
class el_anchor : public html_tag
{
public:
explicit el_anchor(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_anchor : public html_tag {
public:
explicit el_anchor(const std::shared_ptr<litehtml::document>& doc);
void on_click() override;
void apply_stylesheet(const litehtml::css& stylesheet) override;
};
}
void on_click() override;
void apply_stylesheet(const litehtml::css& stylesheet) override;
};
} // namespace litehtml
#endif // LH_EL_ANCHOR_H

View file

@ -3,15 +3,13 @@
#include "html_tag.h"
namespace litehtml
{
class el_base : public html_tag
{
public:
explicit el_base(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_base : public html_tag {
public:
explicit el_base(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
};
}
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_BASE_H

View file

@ -3,38 +3,29 @@
#include "html_tag.h"
namespace litehtml
{
class el_before_after_base : public html_tag
{
public:
el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before);
namespace litehtml {
class el_before_after_base : public html_tag {
public:
el_before_after_base(const std::shared_ptr<litehtml::document>& doc, bool before);
void add_style(const litehtml::style& st) override;
void apply_stylesheet(const litehtml::css& stylesheet) override;
private:
void add_text(const tstring& txt);
void add_function(const tstring& fnc, const tstring& params);
static tstring convert_escape(const tchar_t* txt);
};
void add_style(const litehtml::style& st) override;
void apply_stylesheet(const litehtml::css& stylesheet) override;
class el_before : public el_before_after_base
{
public:
explicit el_before(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, true)
{
private:
void add_text(const tstring& txt);
void add_function(const tstring& fnc, const tstring& params);
static tstring convert_escape(const tchar_t* txt);
};
}
};
class el_before : public el_before_after_base {
public:
explicit el_before(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, true) {}
};
class el_after : public el_before_after_base
{
public:
explicit el_after(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, false)
{
}
};
}
class el_after : public el_before_after_base {
public:
explicit el_after(const std::shared_ptr<litehtml::document>& doc) : el_before_after_base(doc, false) {}
};
} // namespace litehtml
#endif // LH_EL_BEFORE_AFTER_H

View file

@ -3,15 +3,13 @@
#include "html_tag.h"
namespace litehtml
{
class el_body : public html_tag
{
public:
explicit el_body(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_body : public html_tag {
public:
explicit el_body(const std::shared_ptr<litehtml::document>& doc);
bool is_body() const override;
};
}
bool is_body() const override;
};
} // namespace litehtml
#endif // LH_EL_BODY_H

View file

@ -3,15 +3,13 @@
#include "html_tag.h"
namespace litehtml
{
class el_break : public html_tag
{
public:
explicit el_break(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_break : public html_tag {
public:
explicit el_break(const std::shared_ptr<litehtml::document>& doc);
bool is_break() const override;
};
}
bool is_break() const override;
};
} // namespace litehtml
#endif // LH_EL_BREAK_H

View file

@ -3,17 +3,16 @@
#include "html_tag.h"
namespace litehtml
{
class el_cdata : public element
{
tstring m_text;
public:
explicit el_cdata(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_cdata : public element {
tstring m_text;
void get_text(tstring& text) override;
void set_data(const tchar_t* data) override;
};
}
public:
explicit el_cdata(const std::shared_ptr<litehtml::document>& doc);
void get_text(tstring& text) override;
void set_data(const tchar_t* data) override;
};
} // namespace litehtml
#endif // LH_EL_CDATA_H

View file

@ -3,17 +3,16 @@
#include "html_tag.h"
namespace litehtml
{
class el_comment : public element
{
tstring m_text;
public:
explicit el_comment(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_comment : public element {
tstring m_text;
void get_text(tstring& text) override;
void set_data(const tchar_t* data) override;
};
}
public:
explicit el_comment(const std::shared_ptr<litehtml::document>& doc);
void get_text(tstring& text) override;
void set_data(const tchar_t* data) override;
};
} // namespace litehtml
#endif // LH_EL_COMMENT_H

View file

@ -3,15 +3,13 @@
#include "html_tag.h"
namespace litehtml
{
class el_div : public html_tag
{
public:
explicit el_div(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_div : public html_tag {
public:
explicit el_div(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
};
}
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_DIV_H

View file

@ -3,15 +3,13 @@
#include "html_tag.h"
namespace litehtml
{
class el_font : public html_tag
{
public:
explicit el_font(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_font : public html_tag {
public:
explicit el_font(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
};
}
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_FONT_H

View file

@ -3,26 +3,26 @@
#include "html_tag.h"
namespace litehtml
{
namespace litehtml {
class el_image : public html_tag
{
tstring m_src;
public:
el_image(const std::shared_ptr<litehtml::document>& doc);
virtual ~el_image(void);
class el_image : public html_tag {
tstring m_src;
virtual int line_height() const override;
virtual bool is_replaced() const override;
virtual int render(int x, int y, int max_width, bool second_pass = false) override;
virtual void parse_attributes() override;
virtual void parse_styles(bool is_reparse = false) override;
virtual void draw(uint_ptr hdc, int x, int y, const position* clip) override;
virtual void get_content_size(size& sz, int max_width) override;
private:
int calc_max_height(int image_height);
};
}
public:
el_image(const std::shared_ptr<litehtml::document>& doc);
virtual ~el_image(void);
virtual int line_height() const override;
virtual bool is_replaced() const override;
virtual int render(int x, int y, int max_width, bool second_pass = false) override;
virtual void parse_attributes() override;
virtual void parse_styles(bool is_reparse = false) override;
virtual void draw(uint_ptr hdc, int x, int y, const position* clip) override;
virtual void get_content_size(size& sz, int max_width) override;
private:
int calc_max_height(int image_height);
};
} // namespace litehtml
#endif // LH_EL_IMAGE_H

View file

@ -3,18 +3,16 @@
#include "html_tag.h"
namespace litehtml
{
class el_li : public html_tag
{
public:
explicit el_li(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_li : public html_tag {
public:
explicit el_li(const std::shared_ptr<litehtml::document>& doc);
int render(int x, int y, int max_width, bool second_pass = false) override;
int render(int x, int y, int max_width, bool second_pass = false) override;
private:
bool m_index_initialized = false;
};
}
private:
bool m_index_initialized = false;
};
} // namespace litehtml
#endif // LH_EL_LI_H

View file

@ -3,16 +3,14 @@
#include "html_tag.h"
namespace litehtml
{
class el_link : public html_tag
{
public:
explicit el_link(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_link : public html_tag {
public:
explicit el_link(const std::shared_ptr<litehtml::document>& doc);
protected:
void parse_attributes() override;
};
}
protected:
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_LINK_H

View file

@ -3,16 +3,13 @@
#include "html_tag.h"
namespace litehtml
{
class el_para : public html_tag
{
public:
explicit el_para(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_para : public html_tag {
public:
explicit el_para(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
};
}
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_PARA_H

View file

@ -3,18 +3,17 @@
#include "html_tag.h"
namespace litehtml
{
class el_script : public element
{
tstring m_text;
public:
explicit el_script(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_script : public element {
tstring m_text;
void parse_attributes() override;
bool appendChild(const ptr &el) override;
const tchar_t* get_tagName() const override;
};
}
public:
explicit el_script(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
bool appendChild(const ptr& el) override;
const tchar_t* get_tagName() const override;
};
} // namespace litehtml
#endif // LH_EL_SCRIPT_H

View file

@ -1,19 +1,17 @@
#ifndef LH_EL_SPACE_H
#define LH_EL_SPACE_H
#include "html_tag.h"
#include "el_text.h"
#include "html_tag.h"
namespace litehtml
{
class el_space : public el_text
{
public:
el_space(const tchar_t* text, const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_space : public el_text {
public:
el_space(const tchar_t* text, const std::shared_ptr<litehtml::document>& doc);
bool is_white_space() const override;
bool is_break() const override;
};
}
bool is_white_space() const override;
bool is_break() const override;
};
} // namespace litehtml
#endif // LH_EL_SPACE_H

View file

@ -3,18 +3,17 @@
#include "html_tag.h"
namespace litehtml
{
class el_style : public element
{
elements_vector m_children;
public:
explicit el_style(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_style : public element {
elements_vector m_children;
void parse_attributes() override;
bool appendChild(const ptr &el) override;
const tchar_t* get_tagName() const override;
};
}
public:
explicit el_style(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
bool appendChild(const ptr& el) override;
const tchar_t* get_tagName() const override;
};
} // namespace litehtml
#endif // LH_EL_STYLE_H

View file

@ -3,24 +3,20 @@
#include "html_tag.h"
namespace litehtml
{
struct col_info
{
int width;
bool is_auto;
};
namespace litehtml {
struct col_info {
int width;
bool is_auto;
};
class el_table : public html_tag {
public:
explicit el_table(const std::shared_ptr<litehtml::document>& doc);
class el_table : public html_tag
{
public:
explicit el_table(const std::shared_ptr<litehtml::document>& doc);
bool appendChild(const litehtml::element::ptr& el) override;
void parse_styles(bool is_reparse = false) override;
void parse_attributes() override;
};
}
bool appendChild(const litehtml::element::ptr& el) override;
void parse_styles(bool is_reparse = false) override;
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_TABLE_H

View file

@ -3,15 +3,13 @@
#include "html_tag.h"
namespace litehtml
{
class el_td : public html_tag
{
public:
explicit el_td(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_td : public html_tag {
public:
explicit el_td(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
};
}
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_TD_H

View file

@ -3,35 +3,34 @@
#include "html_tag.h"
namespace litehtml
{
class el_text : public element
{
protected:
tstring m_text;
tstring m_transformed_text;
size m_size;
text_transform m_text_transform;
bool m_use_transformed;
bool m_draw_spaces;
public:
el_text(const tchar_t* text, const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_text : public element {
protected:
tstring m_text;
tstring m_transformed_text;
size m_size;
text_transform m_text_transform;
bool m_use_transformed;
bool m_draw_spaces;
void get_text(tstring& text) override;
const tchar_t* get_style_property(const tchar_t* name, bool inherited, const tchar_t* def = nullptr) override;
void parse_styles(bool is_reparse) override;
int get_base_line() override;
void draw(uint_ptr hdc, int x, int y, const position* clip) override;
int line_height() const override;
uint_ptr get_font(font_metrics* fm = nullptr) override;
style_display get_display() const override;
white_space get_white_space() const override;
element_position get_element_position(css_offsets* offsets = nullptr) const override;
css_offsets get_css_offsets() const override;
public:
el_text(const tchar_t* text, const std::shared_ptr<litehtml::document>& doc);
protected:
void get_content_size(size& sz, int max_width) override;
};
}
void get_text(tstring& text) override;
const tchar_t* get_style_property(const tchar_t* name, bool inherited, const tchar_t* def = nullptr) override;
void parse_styles(bool is_reparse) override;
int get_base_line() override;
void draw(uint_ptr hdc, int x, int y, const position* clip) override;
int line_height() const override;
uint_ptr get_font(font_metrics* fm = nullptr) override;
style_display get_display() const override;
white_space get_white_space() const override;
element_position get_element_position(css_offsets* offsets = nullptr) const override;
css_offsets get_css_offsets() const override;
protected:
void get_content_size(size& sz, int max_width) override;
};
} // namespace litehtml
#endif // LH_EL_TEXT_H

View file

@ -3,16 +3,14 @@
#include "html_tag.h"
namespace litehtml
{
class el_title : public html_tag
{
public:
explicit el_title(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_title : public html_tag {
public:
explicit el_title(const std::shared_ptr<litehtml::document>& doc);
protected:
void parse_attributes() override;
};
}
protected:
void parse_attributes() override;
};
} // namespace litehtml
#endif // LH_EL_TITLE_H

View file

@ -3,16 +3,14 @@
#include "html_tag.h"
namespace litehtml
{
class el_tr : public html_tag
{
public:
explicit el_tr(const std::shared_ptr<litehtml::document>& doc);
namespace litehtml {
class el_tr : public html_tag {
public:
explicit el_tr(const std::shared_ptr<litehtml::document>& doc);
void parse_attributes() override;
void get_inline_boxes(position::vector& boxes) override;
};
}
void parse_attributes() override;
void get_inline_boxes(position::vector& boxes) override;
};
} // namespace litehtml
#endif // LH_EL_TR_H

View file

@ -2,403 +2,297 @@
#define LH_ELEMENT_H
#include <memory>
#include "stylesheet.h"
#include "css_offsets.h"
#include "stylesheet.h"
namespace litehtml
{
class box;
namespace litehtml {
class box;
class element : public std::enable_shared_from_this<element>
{
friend class block_box;
friend class line_box;
friend class html_tag;
friend class el_table;
friend class document;
public:
typedef std::shared_ptr<litehtml::element> ptr;
typedef std::shared_ptr<const litehtml::element> const_ptr;
typedef std::weak_ptr<litehtml::element> weak_ptr;
protected:
std::weak_ptr<element> m_parent;
std::weak_ptr<litehtml::document> m_doc;
litehtml::box* m_box;
elements_vector m_children;
position m_pos;
margins m_margins;
margins m_padding;
margins m_borders;
bool m_skip;
class element : public std::enable_shared_from_this<element> {
friend class block_box;
friend class line_box;
friend class html_tag;
friend class el_table;
friend class document;
virtual void select_all(const css_selector& selector, elements_vector& res);
public:
explicit element(const std::shared_ptr<litehtml::document>& doc);
virtual ~element() = default;
public:
typedef std::shared_ptr<litehtml::element> ptr;
typedef std::shared_ptr<const litehtml::element> const_ptr;
typedef std::weak_ptr<litehtml::element> weak_ptr;
// returns refer to m_pos member;
position& get_position();
protected:
std::weak_ptr<element> m_parent;
std::weak_ptr<litehtml::document> m_doc;
litehtml::box* m_box;
elements_vector m_children;
position m_pos;
margins m_margins;
margins m_padding;
margins m_borders;
bool m_skip;
int left() const;
int right() const;
int top() const;
int bottom() const;
int height() const;
int width() const;
virtual void select_all(const css_selector& selector, elements_vector& res);
int content_margins_top() const;
int content_margins_bottom() const;
int content_margins_left() const;
int content_margins_right() const;
int content_margins_width() const;
int content_margins_height() const;
public:
explicit element(const std::shared_ptr<litehtml::document>& doc);
virtual ~element() = default;
int margin_top() const;
int margin_bottom() const;
int margin_left() const;
int margin_right() const;
margins get_margins() const;
// returns refer to m_pos member;
position& get_position();
int padding_top() const;
int padding_bottom() const;
int padding_left() const;
int padding_right() const;
margins get_paddings() const;
int left() const;
int right() const;
int top() const;
int bottom() const;
int height() const;
int width() const;
int border_top() const;
int border_bottom() const;
int border_left() const;
int border_right() const;
margins get_borders() const;
int content_margins_top() const;
int content_margins_bottom() const;
int content_margins_left() const;
int content_margins_right() const;
int content_margins_width() const;
int content_margins_height() const;
bool in_normal_flow() const;
litehtml::web_color get_color(const tchar_t* prop_name, bool inherited, const litehtml::web_color& def_color = litehtml::web_color());
bool is_inline_box() const;
position get_placement() const;
bool collapse_top_margin() const;
bool collapse_bottom_margin() const;
bool is_positioned() const;
int margin_top() const;
int margin_bottom() const;
int margin_left() const;
int margin_right() const;
margins get_margins() const;
bool skip() const;
void skip(bool val);
bool have_parent() const;
element::ptr parent() const;
void parent(const element::ptr& par);
bool is_visible() const;
int calc_width(int defVal) const;
int get_inline_shift_left();
int get_inline_shift_right();
void apply_relative_shift(int parent_width);
int padding_top() const;
int padding_bottom() const;
int padding_left() const;
int padding_right() const;
margins get_paddings() const;
std::shared_ptr<document> get_document() const;
int border_top() const;
int border_bottom() const;
int border_left() const;
int border_right() const;
margins get_borders() const;
virtual elements_vector select_all(const tstring& selector);
virtual elements_vector select_all(const css_selector& selector);
bool in_normal_flow() const;
litehtml::web_color get_color(const tchar_t* prop_name, bool inherited, const litehtml::web_color& def_color = litehtml::web_color());
bool is_inline_box() const;
position get_placement() const;
bool collapse_top_margin() const;
bool collapse_bottom_margin() const;
bool is_positioned() const;
virtual element::ptr select_one(const tstring& selector);
virtual element::ptr select_one(const css_selector& selector);
bool skip() const;
void skip(bool val);
bool have_parent() const;
element::ptr parent() const;
void parent(const element::ptr& par);
bool is_visible() const;
int calc_width(int defVal) const;
int get_inline_shift_left();
int get_inline_shift_right();
void apply_relative_shift(int parent_width);
virtual int render(int x, int y, int max_width, bool second_pass = false);
virtual int render_inline(const ptr &container, int max_width);
virtual int place_element(const ptr &el, int max_width);
virtual void calc_outlines( int parent_width );
virtual void calc_auto_margins(int parent_width);
virtual void apply_vertical_align();
virtual bool fetch_positioned();
virtual void render_positioned(render_type rt = render_all);
std::shared_ptr<document> get_document() const;
virtual bool appendChild(const ptr &el);
virtual bool removeChild(const ptr &el);
virtual void clearRecursive();
virtual elements_vector select_all(const tstring& selector);
virtual elements_vector select_all(const css_selector& selector);
virtual const tchar_t* get_tagName() const;
virtual void set_tagName(const tchar_t* tag);
virtual void set_data(const tchar_t* data);
virtual element_float get_float() const;
virtual vertical_align get_vertical_align() const;
virtual element_clear get_clear() const;
virtual size_t get_children_count() const;
virtual element::ptr get_child(int idx) const;
virtual overflow get_overflow() const;
virtual element::ptr select_one(const tstring& selector);
virtual element::ptr select_one(const css_selector& selector);
virtual css_length get_css_left() const;
virtual css_length get_css_right() const;
virtual css_length get_css_top() const;
virtual css_length get_css_bottom() const;
virtual css_offsets get_css_offsets() const;
virtual css_length get_css_width() const;
virtual void set_css_width(css_length& w);
virtual css_length get_css_height() const;
virtual int render(int x, int y, int max_width, bool second_pass = false);
virtual int render_inline(const ptr& container, int max_width);
virtual int place_element(const ptr& el, int max_width);
virtual void calc_outlines(int parent_width);
virtual void calc_auto_margins(int parent_width);
virtual void apply_vertical_align();
virtual bool fetch_positioned();
virtual void render_positioned(render_type rt = render_all);
virtual void set_attr(const tchar_t* name, const tchar_t* val);
virtual const tchar_t* get_attr(const tchar_t* name, const tchar_t* def = nullptr) const;
virtual void apply_stylesheet(const litehtml::css& stylesheet);
virtual void refresh_styles();
virtual bool is_white_space() const;
virtual bool is_body() const;
virtual bool is_break() const;
virtual int get_base_line();
virtual bool on_mouse_over();
virtual bool on_mouse_leave();
virtual bool on_lbutton_down();
virtual bool on_lbutton_up();
virtual void on_click();
virtual bool find_styles_changes(position::vector& redraw_boxes, int x, int y);
virtual const tchar_t* get_cursor();
virtual void init_font();
virtual bool is_point_inside(int x, int y);
virtual bool set_pseudo_class(const tchar_t* pclass, bool add);
virtual bool set_class(const tchar_t* pclass, bool add);
virtual bool is_replaced() const;
virtual int line_height() const;
virtual white_space get_white_space() const;
virtual style_display get_display() const;
virtual visibility get_visibility() const;
virtual element_position get_element_position(css_offsets* offsets = nullptr) const;
virtual void get_inline_boxes(position::vector& boxes);
virtual void parse_styles(bool is_reparse = false);
virtual void draw(uint_ptr hdc, int x, int y, const position* clip);
virtual void draw_background( uint_ptr hdc, int x, int y, const position* clip );
virtual const tchar_t* get_style_property(const tchar_t* name, bool inherited, const tchar_t* def = nullptr);
virtual uint_ptr get_font(font_metrics* fm = nullptr);
virtual int get_font_size() const;
virtual void get_text(tstring& text);
virtual void parse_attributes();
virtual int select(const css_selector& selector, bool apply_pseudo = true);
virtual int select(const css_element_selector& selector, bool apply_pseudo = true);
virtual element::ptr find_ancestor(const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual bool is_ancestor(const ptr &el) const;
virtual element::ptr find_adjacent_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual element::ptr find_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual bool is_first_child_inline(const element::ptr& el) const;
virtual bool is_last_child_inline(const element::ptr& el);
virtual bool have_inline_child() const;
virtual void get_content_size(size& sz, int max_width);
virtual void init();
virtual bool is_floats_holder() const;
virtual int get_floats_height(element_float el_float = float_none) const;
virtual int get_left_floats_height() const;
virtual int get_right_floats_height() const;
virtual int get_line_left(int y);
virtual int get_line_right(int y, int def_right);
virtual void get_line_left_right(int y, int def_right, int& ln_left, int& ln_right);
virtual void add_float(const ptr &el, int x, int y);
virtual void update_floats(int dy, const ptr &parent);
virtual void add_positioned(const ptr &el);
virtual int find_next_line_top(int top, int width, int def_right);
virtual int get_zindex() const;
virtual void draw_stacking_context(uint_ptr hdc, int x, int y, const position* clip, bool with_positioned);
virtual void draw_children( uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex );
virtual bool is_nth_child(const element::ptr& el, int num, int off, bool of_type) const;
virtual bool is_nth_last_child(const element::ptr& el, int num, int off, bool of_type) const;
virtual bool is_only_child(const element::ptr& el, bool of_type) const;
virtual bool get_predefined_height(int& p_height) const;
virtual void calc_document_size(litehtml::size& sz, int x = 0, int y = 0);
virtual void get_redraw_box(litehtml::position& pos, int x = 0, int y = 0);
virtual void add_style(const litehtml::style& st);
virtual element::ptr get_element_by_point(int x, int y, int client_x, int client_y);
virtual element::ptr get_child_by_point(int x, int y, int client_x, int client_y, draw_flag flag, int zindex);
virtual const background* get_background(bool own_only = false);
};
virtual bool appendChild(const ptr& el);
virtual bool removeChild(const ptr& el);
virtual void clearRecursive();
//////////////////////////////////////////////////////////////////////////
// INLINE FUNCTIONS //
//////////////////////////////////////////////////////////////////////////
virtual const tchar_t* get_tagName() const;
virtual void set_tagName(const tchar_t* tag);
virtual void set_data(const tchar_t* data);
virtual element_float get_float() const;
virtual vertical_align get_vertical_align() const;
virtual element_clear get_clear() const;
virtual size_t get_children_count() const;
virtual element::ptr get_child(int idx) const;
virtual overflow get_overflow() const;
inline int litehtml::element::right() const
{
return left() + width();
}
virtual css_length get_css_left() const;
virtual css_length get_css_right() const;
virtual css_length get_css_top() const;
virtual css_length get_css_bottom() const;
virtual css_offsets get_css_offsets() const;
virtual css_length get_css_width() const;
virtual void set_css_width(css_length& w);
virtual css_length get_css_height() const;
inline int litehtml::element::left() const
{
return m_pos.left() - margin_left() - m_padding.left - m_borders.left;
}
virtual void set_attr(const tchar_t* name, const tchar_t* val);
virtual const tchar_t* get_attr(const tchar_t* name, const tchar_t* def = nullptr) const;
virtual void apply_stylesheet(const litehtml::css& stylesheet);
virtual void refresh_styles();
virtual bool is_white_space() const;
virtual bool is_body() const;
virtual bool is_break() const;
virtual int get_base_line();
virtual bool on_mouse_over();
virtual bool on_mouse_leave();
virtual bool on_lbutton_down();
virtual bool on_lbutton_up();
virtual void on_click();
virtual bool find_styles_changes(position::vector& redraw_boxes, int x, int y);
virtual const tchar_t* get_cursor();
virtual void init_font();
virtual bool is_point_inside(int x, int y);
virtual bool set_pseudo_class(const tchar_t* pclass, bool add);
virtual bool set_class(const tchar_t* pclass, bool add);
virtual bool is_replaced() const;
virtual int line_height() const;
virtual white_space get_white_space() const;
virtual style_display get_display() const;
virtual visibility get_visibility() const;
virtual element_position get_element_position(css_offsets* offsets = nullptr) const;
virtual void get_inline_boxes(position::vector& boxes);
virtual void parse_styles(bool is_reparse = false);
virtual void draw(uint_ptr hdc, int x, int y, const position* clip);
virtual void draw_background(uint_ptr hdc, int x, int y, const position* clip);
virtual const tchar_t* get_style_property(const tchar_t* name, bool inherited, const tchar_t* def = nullptr);
virtual uint_ptr get_font(font_metrics* fm = nullptr);
virtual int get_font_size() const;
virtual void get_text(tstring& text);
virtual void parse_attributes();
virtual int select(const css_selector& selector, bool apply_pseudo = true);
virtual int select(const css_element_selector& selector, bool apply_pseudo = true);
virtual element::ptr find_ancestor(const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual bool is_ancestor(const ptr& el) const;
virtual element::ptr find_adjacent_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual element::ptr find_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr);
virtual bool is_first_child_inline(const element::ptr& el) const;
virtual bool is_last_child_inline(const element::ptr& el);
virtual bool have_inline_child() const;
virtual void get_content_size(size& sz, int max_width);
virtual void init();
virtual bool is_floats_holder() const;
virtual int get_floats_height(element_float el_float = float_none) const;
virtual int get_left_floats_height() const;
virtual int get_right_floats_height() const;
virtual int get_line_left(int y);
virtual int get_line_right(int y, int def_right);
virtual void get_line_left_right(int y, int def_right, int& ln_left, int& ln_right);
virtual void add_float(const ptr& el, int x, int y);
virtual void update_floats(int dy, const ptr& parent);
virtual void add_positioned(const ptr& el);
virtual int find_next_line_top(int top, int width, int def_right);
virtual int get_zindex() const;
virtual void draw_stacking_context(uint_ptr hdc, int x, int y, const position* clip, bool with_positioned);
virtual void draw_children(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex);
virtual bool is_nth_child(const element::ptr& el, int num, int off, bool of_type) const;
virtual bool is_nth_last_child(const element::ptr& el, int num, int off, bool of_type) const;
virtual bool is_only_child(const element::ptr& el, bool of_type) const;
virtual bool get_predefined_height(int& p_height) const;
virtual void calc_document_size(litehtml::size& sz, int x = 0, int y = 0);
virtual void get_redraw_box(litehtml::position& pos, int x = 0, int y = 0);
virtual void add_style(const litehtml::style& st);
virtual element::ptr get_element_by_point(int x, int y, int client_x, int client_y);
virtual element::ptr get_child_by_point(int x, int y, int client_x, int client_y, draw_flag flag, int zindex);
virtual const background* get_background(bool own_only = false);
};
inline int litehtml::element::top() const
{
return m_pos.top() - margin_top() - m_padding.top - m_borders.top;
}
//////////////////////////////////////////////////////////////////////////
// INLINE FUNCTIONS //
//////////////////////////////////////////////////////////////////////////
inline int litehtml::element::bottom() const
{
return top() + height();
}
inline int litehtml::element::right() const { return left() + width(); }
inline int litehtml::element::height() const
{
return m_pos.height + margin_top() + margin_bottom() + m_padding.height() + m_borders.height();
}
inline int litehtml::element::left() const { return m_pos.left() - margin_left() - m_padding.left - m_borders.left; }
inline int litehtml::element::width() const
{
return m_pos.width + margin_left() + margin_right() + m_padding.width() + m_borders.width();
}
inline int litehtml::element::top() const { return m_pos.top() - margin_top() - m_padding.top - m_borders.top; }
inline int litehtml::element::content_margins_top() const
{
return margin_top() + m_padding.top + m_borders.top;
}
inline int litehtml::element::bottom() const { return top() + height(); }
inline int litehtml::element::content_margins_bottom() const
{
return margin_bottom() + m_padding.bottom + m_borders.bottom;
}
inline int litehtml::element::height() const { return m_pos.height + margin_top() + margin_bottom() + m_padding.height() + m_borders.height(); }
inline int litehtml::element::content_margins_left() const
{
return margin_left() + m_padding.left + m_borders.left;
}
inline int litehtml::element::width() const { return m_pos.width + margin_left() + margin_right() + m_padding.width() + m_borders.width(); }
inline int litehtml::element::content_margins_right() const
{
return margin_right() + m_padding.right + m_borders.right;
}
inline int litehtml::element::content_margins_top() const { return margin_top() + m_padding.top + m_borders.top; }
inline int litehtml::element::content_margins_width() const
{
return content_margins_left() + content_margins_right();
}
inline int litehtml::element::content_margins_bottom() const { return margin_bottom() + m_padding.bottom + m_borders.bottom; }
inline int litehtml::element::content_margins_height() const
{
return content_margins_top() + content_margins_bottom();
}
inline int litehtml::element::content_margins_left() const { return margin_left() + m_padding.left + m_borders.left; }
inline litehtml::margins litehtml::element::get_paddings() const
{
return m_padding;
}
inline int litehtml::element::content_margins_right() const { return margin_right() + m_padding.right + m_borders.right; }
inline litehtml::margins litehtml::element::get_borders() const
{
return m_borders;
}
inline int litehtml::element::content_margins_width() const { return content_margins_left() + content_margins_right(); }
inline int litehtml::element::padding_top() const
{
return m_padding.top;
}
inline int litehtml::element::content_margins_height() const { return content_margins_top() + content_margins_bottom(); }
inline int litehtml::element::padding_bottom() const
{
return m_padding.bottom;
}
inline litehtml::margins litehtml::element::get_paddings() const { return m_padding; }
inline int litehtml::element::padding_left() const
{
return m_padding.left;
}
inline litehtml::margins litehtml::element::get_borders() const { return m_borders; }
inline int litehtml::element::padding_right() const
{
return m_padding.right;
}
inline int litehtml::element::padding_top() const { return m_padding.top; }
inline bool litehtml::element::in_normal_flow() const
{
if(get_element_position() != element_position_absolute && get_display() != display_none)
{
return true;
}
return false;
}
inline int litehtml::element::padding_bottom() const { return m_padding.bottom; }
inline int litehtml::element::border_top() const
{
return m_borders.top;
}
inline int litehtml::element::padding_left() const { return m_padding.left; }
inline int litehtml::element::border_bottom() const
{
return m_borders.bottom;
}
inline int litehtml::element::padding_right() const { return m_padding.right; }
inline int litehtml::element::border_left() const
{
return m_borders.left;
}
inline int litehtml::element::border_right() const
{
return m_borders.right;
}
inline bool litehtml::element::skip() const
{
return m_skip;
}
inline void litehtml::element::skip(bool val)
{
m_skip = val;
}
inline bool litehtml::element::have_parent() const
{
return !m_parent.expired();
}
inline element::ptr litehtml::element::parent() const
{
return m_parent.lock();
}
inline void litehtml::element::parent(const element::ptr& par)
{
m_parent = par;
}
inline int litehtml::element::margin_top() const
{
return m_margins.top;
}
inline int litehtml::element::margin_bottom() const
{
return m_margins.bottom;
}
inline int litehtml::element::margin_left() const
{
return m_margins.left;
}
inline int litehtml::element::margin_right() const
{
return m_margins.right;
}
inline litehtml::margins litehtml::element::get_margins() const
{
margins ret;
ret.left = margin_left();
ret.right = margin_right();
ret.top = margin_top();
ret.bottom = margin_bottom();
return ret;
}
inline bool litehtml::element::is_positioned() const
{
return (get_element_position() > element_position_static);
}
inline bool litehtml::element::is_visible() const
{
return !(m_skip || get_display() == display_none || get_visibility() != visibility_visible);
}
inline position& litehtml::element::get_position()
{
return m_pos;
}
inline std::shared_ptr<document> element::get_document() const
{
return m_doc.lock();
}
inline bool litehtml::element::in_normal_flow() const {
if (get_element_position() != element_position_absolute && get_display() != display_none) {
return true;
}
return false;
}
inline int litehtml::element::border_top() const { return m_borders.top; }
inline int litehtml::element::border_bottom() const { return m_borders.bottom; }
inline int litehtml::element::border_left() const { return m_borders.left; }
inline int litehtml::element::border_right() const { return m_borders.right; }
inline bool litehtml::element::skip() const { return m_skip; }
inline void litehtml::element::skip(bool val) { m_skip = val; }
inline bool litehtml::element::have_parent() const { return !m_parent.expired(); }
inline element::ptr litehtml::element::parent() const { return m_parent.lock(); }
inline void litehtml::element::parent(const element::ptr& par) { m_parent = par; }
inline int litehtml::element::margin_top() const { return m_margins.top; }
inline int litehtml::element::margin_bottom() const { return m_margins.bottom; }
inline int litehtml::element::margin_left() const { return m_margins.left; }
inline int litehtml::element::margin_right() const { return m_margins.right; }
inline litehtml::margins litehtml::element::get_margins() const {
margins ret;
ret.left = margin_left();
ret.right = margin_right();
ret.top = margin_top();
ret.bottom = margin_bottom();
return ret;
}
inline bool litehtml::element::is_positioned() const { return (get_element_position() > element_position_static); }
inline bool litehtml::element::is_visible() const { return !(m_skip || get_display() == display_none || get_visibility() != visibility_visible); }
inline position& litehtml::element::get_position() { return m_pos; }
inline std::shared_ptr<document> element::get_document() const { return m_doc.lock(); }
} // namespace litehtml
#endif // LH_ELEMENT_H

View file

@ -1,117 +1,104 @@
#ifndef LH_HTML_H
#define LH_HTML_H
#include <stdlib.h>
#include <string>
#include <ctype.h>
#include <vector>
#include <map>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <functional>
#include "os_types.h"
#include "types.h"
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include "background.h"
#include "borders.h"
#include "html_tag.h"
#include "web_color.h"
#include "media_query.h"
#include "os_types.h"
#include "types.h"
#include "web_color.h"
namespace litehtml
{
struct list_marker
{
tstring image;
const tchar_t* baseurl;
list_style_type marker_type;
web_color color;
position pos;
int index;
uint_ptr font;
};
namespace litehtml {
struct list_marker {
tstring image;
const tchar_t* baseurl;
list_style_type marker_type;
web_color color;
position pos;
int index;
uint_ptr font;
};
// call back interface to draw text, images and other elements
class document_container
{
public:
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) = 0;
virtual void delete_font(litehtml::uint_ptr hFont) = 0;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) = 0;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) = 0;
virtual int pt_to_px(int pt) const = 0;
virtual int get_default_font_size() const = 0;
virtual const litehtml::tchar_t* get_default_font_name() const = 0;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) = 0;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) = 0;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) = 0;
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) = 0;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) = 0;
// call back interface to draw text, images and other elements
class document_container {
public:
virtual litehtml::uint_ptr create_font(const litehtml::tchar_t* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) = 0;
virtual void delete_font(litehtml::uint_ptr hFont) = 0;
virtual int text_width(const litehtml::tchar_t* text, litehtml::uint_ptr hFont) = 0;
virtual void draw_text(litehtml::uint_ptr hdc, const litehtml::tchar_t* text, litehtml::uint_ptr hFont, litehtml::web_color color, const litehtml::position& pos) = 0;
virtual int pt_to_px(int pt) const = 0;
virtual int get_default_font_size() const = 0;
virtual const litehtml::tchar_t* get_default_font_name() const = 0;
virtual void draw_list_marker(litehtml::uint_ptr hdc, const litehtml::list_marker& marker) = 0;
virtual void load_image(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, bool redraw_on_ready) = 0;
virtual void get_image_size(const litehtml::tchar_t* src, const litehtml::tchar_t* baseurl, litehtml::size& sz) = 0;
virtual void draw_background(litehtml::uint_ptr hdc, const litehtml::background_paint& bg) = 0;
virtual void draw_borders(litehtml::uint_ptr hdc, const litehtml::borders& borders, const litehtml::position& draw_pos, bool root) = 0;
virtual void set_caption(const litehtml::tchar_t* caption) = 0;
virtual void set_base_url(const litehtml::tchar_t* base_url) = 0;
virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) = 0;
virtual void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) = 0;
virtual void set_cursor(const litehtml::tchar_t* cursor) = 0;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) = 0;
virtual void import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl) = 0;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) = 0;
virtual void del_clip() = 0;
virtual void get_client_rect(litehtml::position& client) const = 0;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t *tag_name,
const litehtml::string_map &attributes,
const std::shared_ptr<litehtml::document> &doc) = 0;
virtual void set_caption(const litehtml::tchar_t* caption) = 0;
virtual void set_base_url(const litehtml::tchar_t* base_url) = 0;
virtual void link(const std::shared_ptr<litehtml::document>& doc, const litehtml::element::ptr& el) = 0;
virtual void on_anchor_click(const litehtml::tchar_t* url, const litehtml::element::ptr& el) = 0;
virtual void set_cursor(const litehtml::tchar_t* cursor) = 0;
virtual void transform_text(litehtml::tstring& text, litehtml::text_transform tt) = 0;
virtual void import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl) = 0;
virtual void set_clip(const litehtml::position& pos, const litehtml::border_radiuses& bdr_radius, bool valid_x, bool valid_y) = 0;
virtual void del_clip() = 0;
virtual void get_client_rect(litehtml::position& client) const = 0;
virtual std::shared_ptr<litehtml::element> create_element(const litehtml::tchar_t* tag_name, const litehtml::string_map& attributes, const std::shared_ptr<litehtml::document>& doc) = 0;
virtual void get_media_features(litehtml::media_features& media) const = 0;
virtual void get_language(litehtml::tstring& language, litehtml::tstring & culture) const = 0;
virtual litehtml::tstring resolve_color(const litehtml::tstring& /*color*/) const { return litehtml::tstring(); }
virtual void split_text(const char* text, const std::function<void(const tchar_t*)>& on_word, const std::function<void(const tchar_t*)>& on_space);
virtual void get_media_features(litehtml::media_features& media) const = 0;
virtual void get_language(litehtml::tstring& language, litehtml::tstring& culture) const = 0;
virtual litehtml::tstring resolve_color(const litehtml::tstring& /*color*/) const { return litehtml::tstring(); }
virtual void split_text(const char* text, const std::function<void(const tchar_t*)>& on_word, const std::function<void(const tchar_t*)>& on_space);
protected:
~document_container() = default;
};
protected:
~document_container() = default;
};
void trim(tstring &s);
void lcase(tstring &s);
int value_index(const tstring& val, const tstring& strings, int defValue = -1, tchar_t delim = _t(';'));
bool value_in_list(const tstring& val, const tstring& strings, tchar_t delim = _t(';'));
tstring::size_type find_close_bracket(const tstring &s, tstring::size_type off, tchar_t open_b = _t('('), tchar_t close_b = _t(')'));
void split_string(const tstring& str, string_vector& tokens, const tstring& delims, const tstring& delims_preserve = _t(""), const tstring& quote = _t("\""));
void join_string(tstring& str, const string_vector& tokens, const tstring& delims);
double t_strtod(const tchar_t* string, tchar_t** endPtr);
void trim(tstring& s);
void lcase(tstring& s);
int value_index(const tstring& val, const tstring& strings, int defValue = -1, tchar_t delim = _t(';'));
bool value_in_list(const tstring& val, const tstring& strings, tchar_t delim = _t(';'));
tstring::size_type find_close_bracket(const tstring& s, tstring::size_type off, tchar_t open_b = _t('('), tchar_t close_b = _t(')'));
void split_string(const tstring& str, string_vector& tokens, const tstring& delims, const tstring& delims_preserve = _t(""), const tstring& quote = _t("\""));
void join_string(tstring& str, const string_vector& tokens, const tstring& delims);
double t_strtod(const tchar_t* string, tchar_t** endPtr);
int t_strcasecmp(const tchar_t *s1, const tchar_t *s2);
int t_strncasecmp(const tchar_t *s1, const tchar_t *s2, size_t n);
int t_strcasecmp(const tchar_t* s1, const tchar_t* s2);
int t_strncasecmp(const tchar_t* s1, const tchar_t* s2, size_t n);
inline int t_isdigit(int c)
{
return (c >= '0' && c <= '9');
}
inline int t_isdigit(int c) { return (c >= '0' && c <= '9'); }
inline int t_tolower(int c)
{
return (c >= 'A' && c <= 'Z' ? c + 'a' - 'A' : c);
}
inline int t_tolower(int c) { return (c >= 'A' && c <= 'Z' ? c + 'a' - 'A' : c); }
inline int round_f(float val)
{
int int_val = (int) val;
if(val - int_val >= 0.5)
{
int_val++;
}
return int_val;
}
inline int round_d(double val)
{
int int_val = (int) val;
if(val - int_val >= 0.5)
{
int_val++;
}
return int_val;
}
inline int round_f(float val) {
int int_val = (int)val;
if (val - int_val >= 0.5) {
int_val++;
}
return int_val;
}
inline int round_d(double val) {
int int_val = (int)val;
if (val - int_val >= 0.5) {
int_val++;
}
return int_val;
}
} // namespace litehtml
#endif // LH_HTML_H

View file

@ -1,248 +1,238 @@
#ifndef LH_HTML_TAG_H
#define LH_HTML_TAG_H
#include "background.h"
#include "borders.h"
#include "box.h"
#include "css_margins.h"
#include "css_selector.h"
#include "element.h"
#include "style.h"
#include "background.h"
#include "css_margins.h"
#include "borders.h"
#include "css_selector.h"
#include "stylesheet.h"
#include "box.h"
#include "table.h"
namespace litehtml
{
struct line_context
{
int calculatedTop;
int top;
int left;
int right;
namespace litehtml {
struct line_context {
int calculatedTop;
int top;
int left;
int right;
int width() const
{
return right - left;
}
void fix_top()
{
calculatedTop = top;
}
};
int width() const { return right - left; }
void fix_top() { calculatedTop = top; }
};
class html_tag : public element
{
friend class elements_iterator;
friend class el_table;
friend class table_grid;
friend class block_box;
friend class line_box;
public:
typedef std::shared_ptr<litehtml::html_tag> ptr;
protected:
box::vector m_boxes;
string_vector m_class_values;
tstring m_tag;
litehtml::style m_style;
string_map m_attrs;
vertical_align m_vertical_align;
text_align m_text_align;
style_display m_display;
list_style_type m_list_style_type;
list_style_position m_list_style_position;
white_space m_white_space;
element_float m_float;
element_clear m_clear;
floated_box::vector m_floats_left;
floated_box::vector m_floats_right;
elements_vector m_positioned;
background m_bg;
element_position m_el_position;
int m_line_height;
bool m_lh_predefined;
string_vector m_pseudo_classes;
used_selector::vector m_used_styles;
class html_tag : public element {
friend class elements_iterator;
friend class el_table;
friend class table_grid;
friend class block_box;
friend class line_box;
uint_ptr m_font;
int m_font_size;
font_metrics m_font_metrics;
public:
typedef std::shared_ptr<litehtml::html_tag> ptr;
css_margins m_css_margins;
css_margins m_css_padding;
css_borders m_css_borders;
css_length m_css_width;
css_length m_css_height;
css_length m_css_min_width;
css_length m_css_min_height;
css_length m_css_max_width;
css_length m_css_max_height;
css_offsets m_css_offsets;
css_length m_css_text_indent;
protected:
box::vector m_boxes;
string_vector m_class_values;
tstring m_tag;
litehtml::style m_style;
string_map m_attrs;
vertical_align m_vertical_align;
text_align m_text_align;
style_display m_display;
list_style_type m_list_style_type;
list_style_position m_list_style_position;
white_space m_white_space;
element_float m_float;
element_clear m_clear;
floated_box::vector m_floats_left;
floated_box::vector m_floats_right;
elements_vector m_positioned;
background m_bg;
element_position m_el_position;
int m_line_height;
bool m_lh_predefined;
string_vector m_pseudo_classes;
used_selector::vector m_used_styles;
overflow m_overflow;
visibility m_visibility;
int m_z_index;
box_sizing m_box_sizing;
uint_ptr m_font;
int m_font_size;
font_metrics m_font_metrics;
int_int_cache m_cahe_line_left;
int_int_cache m_cahe_line_right;
css_margins m_css_margins;
css_margins m_css_padding;
css_borders m_css_borders;
css_length m_css_width;
css_length m_css_height;
css_length m_css_min_width;
css_length m_css_min_height;
css_length m_css_max_width;
css_length m_css_max_height;
css_offsets m_css_offsets;
css_length m_css_text_indent;
// data for table rendering
std::unique_ptr<table_grid> m_grid;
css_length m_css_border_spacing_x;
css_length m_css_border_spacing_y;
int m_border_spacing_x;
int m_border_spacing_y;
border_collapse m_border_collapse;
overflow m_overflow;
visibility m_visibility;
int m_z_index;
box_sizing m_box_sizing;
void select_all(const css_selector& selector, elements_vector& res) override;
int_int_cache m_cahe_line_left;
int_int_cache m_cahe_line_right;
public:
explicit html_tag(const std::shared_ptr<litehtml::document>& doc);
// data for table rendering
std::unique_ptr<table_grid> m_grid;
css_length m_css_border_spacing_x;
css_length m_css_border_spacing_y;
int m_border_spacing_x;
int m_border_spacing_y;
border_collapse m_border_collapse;
/* render functions */
void select_all(const css_selector& selector, elements_vector& res) override;
int render(int x, int y, int max_width, bool second_pass = false) override;
public:
explicit html_tag(const std::shared_ptr<litehtml::document>& doc);
int render_inline(const element::ptr &container, int max_width) override;
int place_element(const element::ptr &el, int max_width) override;
bool fetch_positioned() override;
void render_positioned(render_type rt = render_all) override;
/* render functions */
int new_box(const element::ptr &el, int max_width, line_context& line_ctx);
int render(int x, int y, int max_width, bool second_pass = false) override;
int get_cleared_top(const element::ptr &el, int line_top) const;
int finish_last_box(bool end_of_render = false);
int render_inline(const element::ptr& container, int max_width) override;
int place_element(const element::ptr& el, int max_width) override;
bool fetch_positioned() override;
void render_positioned(render_type rt = render_all) override;
bool appendChild(const element::ptr &el) override;
bool removeChild(const element::ptr &el) override;
void clearRecursive() override;
const tchar_t* get_tagName() const override;
void set_tagName(const tchar_t* tag) override;
void set_data(const tchar_t* data) override;
element_float get_float() const override;
vertical_align get_vertical_align() const override;
css_length get_css_left() const override;
css_length get_css_right() const override;
css_length get_css_top() const override;
css_length get_css_bottom() const override;
css_length get_css_width() const override;
css_offsets get_css_offsets() const override;
void set_css_width(css_length& w) override;
css_length get_css_height() const override;
element_clear get_clear() const override;
size_t get_children_count() const override;
element::ptr get_child(int idx) const override;
element_position get_element_position(css_offsets* offsets = nullptr) const override;
overflow get_overflow() const override;
int new_box(const element::ptr& el, int max_width, line_context& line_ctx);
void set_attr(const tchar_t* name, const tchar_t* val) override;
const tchar_t* get_attr(const tchar_t* name, const tchar_t* def = nullptr) const override;
void apply_stylesheet(const litehtml::css& stylesheet) override;
void refresh_styles() override;
int get_cleared_top(const element::ptr& el, int line_top) const;
int finish_last_box(bool end_of_render = false);
bool is_white_space() const override;
bool is_body() const override;
bool is_break() const override;
int get_base_line() override;
bool on_mouse_over() override;
bool on_mouse_leave() override;
bool on_lbutton_down() override;
bool on_lbutton_up() override;
void on_click() override;
bool find_styles_changes(position::vector& redraw_boxes, int x, int y) override;
const tchar_t* get_cursor() override;
void init_font() override;
bool set_pseudo_class(const tchar_t* pclass, bool add) override;
bool set_class(const tchar_t* pclass, bool add) override;
bool is_replaced() const override;
int line_height() const override;
white_space get_white_space() const override;
style_display get_display() const override;
visibility get_visibility() const override;
void parse_styles(bool is_reparse = false) override;
void draw(uint_ptr hdc, int x, int y, const position* clip) override;
void draw_background(uint_ptr hdc, int x, int y, const position* clip) override;
bool appendChild(const element::ptr& el) override;
bool removeChild(const element::ptr& el) override;
void clearRecursive() override;
const tchar_t* get_tagName() const override;
void set_tagName(const tchar_t* tag) override;
void set_data(const tchar_t* data) override;
element_float get_float() const override;
vertical_align get_vertical_align() const override;
css_length get_css_left() const override;
css_length get_css_right() const override;
css_length get_css_top() const override;
css_length get_css_bottom() const override;
css_length get_css_width() const override;
css_offsets get_css_offsets() const override;
void set_css_width(css_length& w) override;
css_length get_css_height() const override;
element_clear get_clear() const override;
size_t get_children_count() const override;
element::ptr get_child(int idx) const override;
element_position get_element_position(css_offsets* offsets = nullptr) const override;
overflow get_overflow() const override;
const tchar_t* get_style_property(const tchar_t* name, bool inherited, const tchar_t* def = nullptr) override;
uint_ptr get_font(font_metrics* fm = nullptr) override;
int get_font_size() const override;
void set_attr(const tchar_t* name, const tchar_t* val) override;
const tchar_t* get_attr(const tchar_t* name, const tchar_t* def = nullptr) const override;
void apply_stylesheet(const litehtml::css& stylesheet) override;
void refresh_styles() override;
elements_vector& children();
void calc_outlines(int parent_width) override;
void calc_auto_margins(int parent_width) override;
bool is_white_space() const override;
bool is_body() const override;
bool is_break() const override;
int get_base_line() override;
bool on_mouse_over() override;
bool on_mouse_leave() override;
bool on_lbutton_down() override;
bool on_lbutton_up() override;
void on_click() override;
bool find_styles_changes(position::vector& redraw_boxes, int x, int y) override;
const tchar_t* get_cursor() override;
void init_font() override;
bool set_pseudo_class(const tchar_t* pclass, bool add) override;
bool set_class(const tchar_t* pclass, bool add) override;
bool is_replaced() const override;
int line_height() const override;
white_space get_white_space() const override;
style_display get_display() const override;
visibility get_visibility() const override;
void parse_styles(bool is_reparse = false) override;
void draw(uint_ptr hdc, int x, int y, const position* clip) override;
void draw_background(uint_ptr hdc, int x, int y, const position* clip) override;
int select(const css_selector& selector, bool apply_pseudo = true) override;
int select(const css_element_selector& selector, bool apply_pseudo = true) override;
const tchar_t* get_style_property(const tchar_t* name, bool inherited, const tchar_t* def = nullptr) override;
uint_ptr get_font(font_metrics* fm = nullptr) override;
int get_font_size() const override;
elements_vector select_all(const tstring& selector) override;
elements_vector select_all(const css_selector& selector) override;
elements_vector& children();
void calc_outlines(int parent_width) override;
void calc_auto_margins(int parent_width) override;
element::ptr select_one(const tstring& selector) override;
element::ptr select_one(const css_selector& selector) override;
int select(const css_selector& selector, bool apply_pseudo = true) override;
int select(const css_element_selector& selector, bool apply_pseudo = true) override;
element::ptr find_ancestor(const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
element::ptr find_adjacent_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
element::ptr find_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
void get_text(tstring& text) override;
void parse_attributes() override;
elements_vector select_all(const tstring& selector) override;
elements_vector select_all(const css_selector& selector) override;
bool is_first_child_inline(const element::ptr& el) const override;
bool is_last_child_inline(const element::ptr& el) override;
bool have_inline_child() const override;
void get_content_size(size& sz, int max_width) override;
void init() override;
void get_inline_boxes(position::vector& boxes) override;
bool is_floats_holder() const override;
int get_floats_height(element_float el_float = float_none) const override;
int get_left_floats_height() const override;
int get_right_floats_height() const override;
int get_line_left(int y) override;
int get_line_right(int y, int def_right) override;
void get_line_left_right(int y, int def_right, int& ln_left, int& ln_right) override;
void add_float(const element::ptr &el, int x, int y) override;
void update_floats(int dy, const element::ptr &parent) override;
void add_positioned(const element::ptr &el) override;
int find_next_line_top(int top, int width, int def_right) override;
void apply_vertical_align() override;
void draw_children(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex) override;
int get_zindex() const override;
void draw_stacking_context(uint_ptr hdc, int x, int y, const position* clip, bool with_positioned) override;
void calc_document_size(litehtml::size& sz, int x = 0, int y = 0) override;
void get_redraw_box(litehtml::position& pos, int x = 0, int y = 0) override;
void add_style(const litehtml::style& st) override;
element::ptr get_element_by_point(int x, int y, int client_x, int client_y) override;
element::ptr get_child_by_point(int x, int y, int client_x, int client_y, draw_flag flag, int zindex) override;
element::ptr select_one(const tstring& selector) override;
element::ptr select_one(const css_selector& selector) override;
bool is_nth_child(const element::ptr& el, int num, int off, bool of_type) const override;
bool is_nth_last_child(const element::ptr& el, int num, int off, bool of_type) const override;
bool is_only_child(const element::ptr& el, bool of_type) const override;
const background* get_background(bool own_only = false) override;
element::ptr find_ancestor(const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
element::ptr find_adjacent_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
element::ptr find_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
void get_text(tstring& text) override;
void parse_attributes() override;
protected:
void draw_children_box(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex);
void draw_children_table(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex);
int render_box(int x, int y, int max_width, bool second_pass = false);
int render_table(int x, int y, int max_width, bool second_pass = false);
int fix_line_width(int max_width, element_float flt);
void parse_background();
void init_background_paint( position pos, background_paint &bg_paint, const background* bg );
void draw_list_marker( uint_ptr hdc, const position &pos );
tstring get_list_marker_text(int index);
static void parse_nth_child_params( const tstring& param, int &num, int &off );
void remove_before_after();
litehtml::element::ptr get_element_before();
litehtml::element::ptr get_element_after();
};
bool is_first_child_inline(const element::ptr& el) const override;
bool is_last_child_inline(const element::ptr& el) override;
bool have_inline_child() const override;
void get_content_size(size& sz, int max_width) override;
void init() override;
void get_inline_boxes(position::vector& boxes) override;
bool is_floats_holder() const override;
int get_floats_height(element_float el_float = float_none) const override;
int get_left_floats_height() const override;
int get_right_floats_height() const override;
int get_line_left(int y) override;
int get_line_right(int y, int def_right) override;
void get_line_left_right(int y, int def_right, int& ln_left, int& ln_right) override;
void add_float(const element::ptr& el, int x, int y) override;
void update_floats(int dy, const element::ptr& parent) override;
void add_positioned(const element::ptr& el) override;
int find_next_line_top(int top, int width, int def_right) override;
void apply_vertical_align() override;
void draw_children(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex) override;
int get_zindex() const override;
void draw_stacking_context(uint_ptr hdc, int x, int y, const position* clip, bool with_positioned) override;
void calc_document_size(litehtml::size& sz, int x = 0, int y = 0) override;
void get_redraw_box(litehtml::position& pos, int x = 0, int y = 0) override;
void add_style(const litehtml::style& st) override;
element::ptr get_element_by_point(int x, int y, int client_x, int client_y) override;
element::ptr get_child_by_point(int x, int y, int client_x, int client_y, draw_flag flag, int zindex) override;
/************************************************************************/
/* Inline Functions */
/************************************************************************/
bool is_nth_child(const element::ptr& el, int num, int off, bool of_type) const override;
bool is_nth_last_child(const element::ptr& el, int num, int off, bool of_type) const override;
bool is_only_child(const element::ptr& el, bool of_type) const override;
const background* get_background(bool own_only = false) override;
inline elements_vector& litehtml::html_tag::children()
{
return m_children;
}
}
protected:
void draw_children_box(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex);
void draw_children_table(uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex);
int render_box(int x, int y, int max_width, bool second_pass = false);
int render_table(int x, int y, int max_width, bool second_pass = false);
int fix_line_width(int max_width, element_float flt);
void parse_background();
void init_background_paint(position pos, background_paint& bg_paint, const background* bg);
void draw_list_marker(uint_ptr hdc, const position& pos);
tstring get_list_marker_text(int index);
static void parse_nth_child_params(const tstring& param, int& num, int& off);
void remove_before_after();
litehtml::element::ptr get_element_before();
litehtml::element::ptr get_element_after();
};
/************************************************************************/
/* Inline Functions */
/************************************************************************/
inline elements_vector& litehtml::html_tag::children() { return m_children; }
} // namespace litehtml
#endif // LH_HTML_TAG_H

View file

@ -3,87 +3,74 @@
#include "types.h"
namespace litehtml
{
class element;
namespace litehtml {
class element;
class iterator_selector
{
public:
virtual bool select(const element::ptr& el) = 0;
class iterator_selector {
public:
virtual bool select(const element::ptr& el) = 0;
protected:
~iterator_selector() = default;
};
protected:
~iterator_selector() = default;
};
class elements_iterator
{
private:
struct stack_item
{
int idx;
element::ptr el;
stack_item() : idx(0)
{
}
stack_item(const stack_item& val)
{
idx = val.idx;
el = val.el;
}
stack_item(stack_item&& val)
{
idx = val.idx;
el = std::move(val.el);
}
};
class elements_iterator {
private:
struct stack_item {
int idx;
element::ptr el;
stack_item() : idx(0) {}
stack_item(const stack_item& val) {
idx = val.idx;
el = val.el;
}
stack_item(stack_item&& val) {
idx = val.idx;
el = std::move(val.el);
}
};
std::vector<stack_item> m_stack;
element::ptr m_el;
int m_idx;
iterator_selector* m_go_inside;
iterator_selector* m_select;
public:
std::vector<stack_item> m_stack;
element::ptr m_el;
int m_idx;
iterator_selector* m_go_inside;
iterator_selector* m_select;
elements_iterator(const element::ptr& el, iterator_selector* go_inside, iterator_selector* select)
{
m_el = el;
m_idx = -1;
m_go_inside = go_inside;
m_select = select;
}
public:
elements_iterator(const element::ptr& el, iterator_selector* go_inside, iterator_selector* select) {
m_el = el;
m_idx = -1;
m_go_inside = go_inside;
m_select = select;
}
~elements_iterator() = default;
~elements_iterator() = default;
element::ptr next(bool ret_parent = true);
element::ptr next(bool ret_parent = true);
private:
void next_idx();
};
private:
void next_idx();
};
class go_inside_inline final : public iterator_selector
{
public:
bool select(const element::ptr& el) override;
};
class go_inside_inline final : public iterator_selector {
public:
bool select(const element::ptr& el) override;
};
class go_inside_table final : public iterator_selector
{
public:
bool select(const element::ptr& el) override;
};
class go_inside_table final : public iterator_selector {
public:
bool select(const element::ptr& el) override;
};
class table_rows_selector final : public iterator_selector
{
public:
bool select(const element::ptr& el) override;
};
class table_rows_selector final : public iterator_selector {
public:
bool select(const element::ptr& el) override;
};
class table_cells_selector final : public iterator_selector
{
public:
bool select(const element::ptr& el) override;
};
}
class table_cells_selector final : public iterator_selector {
public:
bool select(const element::ptr& el) override;
};
} // namespace litehtml
#endif // LH_ITERATORS_H

View file

@ -1,77 +1,69 @@
#ifndef LH_MEDIA_QUERY_H
#define LH_MEDIA_QUERY_H
namespace litehtml
{
struct media_query_expression
{
typedef std::vector<media_query_expression> vector;
media_feature feature;
int val;
int val2;
bool check_as_bool;
namespace litehtml {
struct media_query_expression {
typedef std::vector<media_query_expression> vector;
media_feature feature;
int val;
int val2;
bool check_as_bool;
media_query_expression()
{
check_as_bool = false;
feature = media_feature_none;
val = 0;
val2 = 0;
}
media_query_expression() {
check_as_bool = false;
feature = media_feature_none;
val = 0;
val2 = 0;
}
bool check(const media_features& features) const;
};
bool check(const media_features& features) const;
};
class media_query
{
public:
typedef std::shared_ptr<media_query> ptr;
typedef std::vector<media_query::ptr> vector;
private:
media_query_expression::vector m_expressions;
bool m_not;
media_type m_media_type;
public:
media_query();
media_query(const media_query& val);
class media_query {
public:
typedef std::shared_ptr<media_query> ptr;
typedef std::vector<media_query::ptr> vector;
static media_query::ptr create_from_string(const tstring& str, const std::shared_ptr<document>& doc);
bool check(const media_features& features) const;
};
private:
media_query_expression::vector m_expressions;
bool m_not;
media_type m_media_type;
class media_query_list
{
public:
typedef std::shared_ptr<media_query_list> ptr;
typedef std::vector<media_query_list::ptr> vector;
private:
media_query::vector m_queries;
bool m_is_used;
public:
media_query_list();
media_query_list(const media_query_list& val);
public:
media_query();
media_query(const media_query& val);
static media_query_list::ptr create_from_string(const tstring& str, const std::shared_ptr<document>& doc);
bool is_used() const;
bool apply_media_features(const media_features& features); // returns true if the m_is_used changed
};
static media_query::ptr create_from_string(const tstring& str, const std::shared_ptr<document>& doc);
bool check(const media_features& features) const;
};
inline media_query_list::media_query_list(const media_query_list& val)
{
m_is_used = val.m_is_used;
m_queries = val.m_queries;
}
class media_query_list {
public:
typedef std::shared_ptr<media_query_list> ptr;
typedef std::vector<media_query_list::ptr> vector;
inline media_query_list::media_query_list()
{
m_is_used = false;
}
private:
media_query::vector m_queries;
bool m_is_used;
inline bool media_query_list::is_used() const
{
return m_is_used;
}
public:
media_query_list();
media_query_list(const media_query_list& val);
static media_query_list::ptr create_from_string(const tstring& str, const std::shared_ptr<document>& doc);
bool is_used() const;
bool apply_media_features(const media_features& features); // returns true if the m_is_used changed
};
inline media_query_list::media_query_list(const media_query_list& val) {
m_is_used = val.m_is_used;
m_queries = val.m_queries;
}
inline media_query_list::media_query_list() { m_is_used = false; }
inline bool media_query_list::is_used() const { return m_is_used; }
} // namespace litehtml
#endif // LH_MEDIA_QUERY_H

View file

@ -2,18 +2,17 @@
#define NUM_CVT_H
#include <string>
#include "os_types.h"
namespace litehtml
{
namespace num_cvt
{
litehtml::tstring to_latin_lower(int val);
litehtml::tstring to_latin_upper(int val);
litehtml::tstring to_greek_lower(int val);
litehtml::tstring to_roman_lower(int value);
litehtml::tstring to_roman_upper(int value);
}
}
namespace litehtml {
namespace num_cvt {
litehtml::tstring to_latin_lower(int val);
litehtml::tstring to_latin_upper(int val);
litehtml::tstring to_greek_lower(int val);
litehtml::tstring to_roman_lower(int value);
litehtml::tstring to_roman_upper(int value);
} // namespace num_cvt
} // namespace litehtml
#endif // NUM_CVT_H
#endif // NUM_CVT_H

View file

@ -1,12 +1,11 @@
#ifndef LH_OS_TYPES_H
#define LH_OS_TYPES_H
#include <string>
#include <cstdint>
#include <string>
namespace litehtml
{
#if defined( WIN32 ) || defined( _WIN32 ) || defined( WINCE )
namespace litehtml {
#if defined(WIN32) || defined(_WIN32) || defined(WINCE)
// noexcept appeared since Visual Studio 2013
#if _MSC_VER < 1900
@ -15,71 +14,71 @@ namespace litehtml
#ifndef LITEHTML_UTF8
typedef std::wstring tstring;
typedef wchar_t tchar_t;
typedef std::wstringstream tstringstream;
typedef std::wstring tstring;
typedef wchar_t tchar_t;
typedef std::wstringstream tstringstream;
#define _t(quote) L##quote
#define _t(quote) L##quote
#define t_strlen wcslen
#define t_strcmp wcscmp
#define t_strncmp wcsncmp
#define t_strtol wcstol
#define t_atoi _wtoi
#define t_itoa(value, buffer, size, radix) _itow_s(value, buffer, size, radix)
#define t_strstr wcsstr
#define t_isspace iswspace
#define t_to_string(val) std::to_wstring(val)
#define t_strlen wcslen
#define t_strcmp wcscmp
#define t_strncmp wcsncmp
#define t_strtol wcstol
#define t_atoi _wtoi
#define t_itoa(value, buffer, size, radix) _itow_s(value, buffer, size, radix)
#define t_strstr wcsstr
#define t_isspace iswspace
#define t_to_string(val) std::to_wstring(val)
#else
typedef std::string tstring;
typedef char tchar_t;
typedef std::stringstream tstringstream;
typedef std::string tstring;
typedef char tchar_t;
typedef std::stringstream tstringstream;
#define _t(quote) quote
#define _t(quote) quote
#define t_strlen strlen
#define t_strcmp strcmp
#define t_strncmp strncmp
#define t_strtol strtol
#define t_atoi atoi
#define t_itoa(value, buffer, size, radix) _itoa_s(value, buffer, size, radix)
#define t_strstr strstr
#define t_isspace isspace
#define t_to_string(val) std::to_string(val)
#define t_strlen strlen
#define t_strcmp strcmp
#define t_strncmp strncmp
#define t_strtol strtol
#define t_atoi atoi
#define t_itoa(value, buffer, size, radix) _itoa_s(value, buffer, size, radix)
#define t_strstr strstr
#define t_isspace isspace
#define t_to_string(val) std::to_string(val)
#endif
#ifdef _WIN64
typedef unsigned __int64 uint_ptr;
#else
typedef unsigned int uint_ptr;
#endif
#ifdef _WIN64
typedef unsigned __int64 uint_ptr;
#else
typedef unsigned int uint_ptr;
#endif
#else
#define LITEHTML_UTF8
#define LITEHTML_UTF8
typedef std::string tstring;
typedef char tchar_t;
typedef std::uintptr_t uint_ptr;
typedef std::stringstream tstringstream;
typedef std::string tstring;
typedef char tchar_t;
typedef std::uintptr_t uint_ptr;
typedef std::stringstream tstringstream;
#define _t(quote) quote
#define _t(quote) quote
#define t_strlen strlen
#define t_strcmp strcmp
#define t_strncmp strncmp
#define t_strlen strlen
#define t_strcmp strcmp
#define t_strncmp strncmp
#define t_itoa(value, buffer, size, radix) snprintf(buffer, size, "%d", value)
#define t_itoa(value, buffer, size, radix) snprintf(buffer, size, "%d", value)
#define t_strtol strtol
#define t_atoi atoi
#define t_strstr strstr
#define t_isspace isspace
#define t_to_string(val) std::to_string(val)
#define t_strtol strtol
#define t_atoi atoi
#define t_strstr strstr
#define t_isspace isspace
#define t_to_string(val) std::to_string(val)
#endif
}
} // namespace litehtml
#endif // LH_OS_TYPES_H

View file

@ -1,95 +1,79 @@
#ifndef LH_STYLE_H
#define LH_STYLE_H
#include "attributes.h"
#include <string>
namespace litehtml
{
class property_value
{
public:
tstring m_value;
bool m_important;
#include "attributes.h"
property_value()
{
m_important = false;
}
property_value(const tchar_t* val, bool imp)
{
m_important = imp;
m_value = val;
}
property_value(const property_value& val)
{
m_value = val.m_value;
m_important = val.m_important;
}
namespace litehtml {
class property_value {
public:
tstring m_value;
bool m_important;
property_value& operator=(const property_value& val)
{
m_value = val.m_value;
m_important = val.m_important;
return *this;
}
};
property_value() { m_important = false; }
property_value(const tchar_t* val, bool imp) {
m_important = imp;
m_value = val;
}
property_value(const property_value& val) {
m_value = val.m_value;
m_important = val.m_important;
}
typedef std::map<tstring, property_value> props_map;
property_value& operator=(const property_value& val) {
m_value = val.m_value;
m_important = val.m_important;
return *this;
}
};
class style
{
public:
typedef std::shared_ptr<style> ptr;
typedef std::vector<style::ptr> vector;
private:
props_map m_properties;
static string_map m_valid_values;
public:
style() = default;
style(const style& val);
typedef std::map<tstring, property_value> props_map;
style& operator=(const style& val)
{
m_properties = val.m_properties;
return *this;
}
class style {
public:
typedef std::shared_ptr<style> ptr;
typedef std::vector<style::ptr> vector;
void add(const tchar_t* txt, const tchar_t* baseurl)
{
parse(txt, baseurl);
}
private:
props_map m_properties;
static string_map m_valid_values;
void add_property(const tchar_t* name, const tchar_t* val, const tchar_t* baseurl, bool important);
public:
style() = default;
style(const style& val);
const tchar_t* get_property(const tchar_t* name) const
{
if(name)
{
auto f = m_properties.find(name);
if(f != m_properties.end())
{
return f->second.m_value.c_str();
}
}
return nullptr;
}
style& operator=(const style& val) {
m_properties = val.m_properties;
return *this;
}
void combine(const litehtml::style& src);
void clear()
{
m_properties.clear();
}
void add(const tchar_t* txt, const tchar_t* baseurl) { parse(txt, baseurl); }
private:
void parse_property(const tstring& txt, const tchar_t* baseurl);
void parse(const tchar_t* txt, const tchar_t* baseurl);
void parse_short_border(const tstring& prefix, const tstring& val, bool important);
void parse_short_background(const tstring& val, const tchar_t* baseurl, bool important);
void parse_short_font(const tstring& val, bool important);
void add_parsed_property(const tstring& name, const tstring& val, bool important);
void remove_property(const tstring& name, bool important);
};
}
void add_property(const tchar_t* name, const tchar_t* val, const tchar_t* baseurl, bool important);
const tchar_t* get_property(const tchar_t* name) const {
if (name) {
auto f = m_properties.find(name);
if (f != m_properties.end()) {
return f->second.m_value.c_str();
}
}
return nullptr;
}
void combine(const litehtml::style& src);
void clear() { m_properties.clear(); }
private:
void parse_property(const tstring& txt, const tchar_t* baseurl);
void parse(const tchar_t* txt, const tchar_t* baseurl);
void parse_short_border(const tstring& prefix, const tstring& val, bool important);
void parse_short_background(const tstring& val, const tchar_t* baseurl, bool important);
void parse_short_font(const tstring& val, bool important);
void add_parsed_property(const tstring& name, const tstring& val, bool important);
void remove_property(const tstring& name, bool important);
};
} // namespace litehtml
#endif // LH_STYLE_H

View file

@ -1,47 +1,38 @@
#ifndef LH_STYLESHEET_H
#define LH_STYLESHEET_H
#include "style.h"
#include "css_selector.h"
#include "style.h"
namespace litehtml
{
class document_container;
namespace litehtml {
class document_container;
class css
{
css_selector::vector m_selectors;
public:
css() = default;
~css() = default;
class css {
css_selector::vector m_selectors;
const css_selector::vector& selectors() const
{
return m_selectors;
}
public:
css() = default;
~css() = default;
void clear()
{
m_selectors.clear();
}
const css_selector::vector& selectors() const { return m_selectors; }
void parse_stylesheet(const tchar_t* str, const tchar_t* baseurl, const std::shared_ptr <document>& doc, const media_query_list::ptr& media);
void sort_selectors();
static void parse_css_url(const tstring& str, tstring& url);
void clear() { m_selectors.clear(); }
private:
void parse_atrule(const tstring& text, const tchar_t* baseurl, const std::shared_ptr<document>& doc, const media_query_list::ptr& media);
void add_selector(const css_selector::ptr& selector);
bool parse_selectors(const tstring& txt, const litehtml::style::ptr& styles, const media_query_list::ptr& media);
void parse_stylesheet(const tchar_t* str, const tchar_t* baseurl, const std::shared_ptr<document>& doc, const media_query_list::ptr& media);
void sort_selectors();
static void parse_css_url(const tstring& str, tstring& url);
};
inline void litehtml::css::add_selector( const css_selector::ptr& selector )
{
selector->m_order = (int) m_selectors.size();
m_selectors.push_back(selector);
}
private:
void parse_atrule(const tstring& text, const tchar_t* baseurl, const std::shared_ptr<document>& doc, const media_query_list::ptr& media);
void add_selector(const css_selector::ptr& selector);
bool parse_selectors(const tstring& txt, const litehtml::style::ptr& styles, const media_query_list::ptr& media);
};
inline void litehtml::css::add_selector(const css_selector::ptr& selector) {
selector->m_order = (int)m_selectors.size();
m_selectors.push_back(selector);
}
} // namespace litehtml
#endif // LH_STYLESHEET_H

View file

@ -1,251 +1,231 @@
#ifndef LH_TABLE_H
#define LH_TABLE_H
namespace litehtml
{
struct table_row
{
typedef std::vector<table_row> vector;
namespace litehtml {
struct table_row {
typedef std::vector<table_row> vector;
int height;
int border_top;
int border_bottom;
element::ptr el_row;
int top;
int bottom;
css_length css_height;
int min_height;
int height;
int border_top;
int border_bottom;
element::ptr el_row;
int top;
int bottom;
css_length css_height;
int min_height;
table_row()
{
min_height = 0;
top = 0;
bottom = 0;
border_bottom = 0;
border_top = 0;
height = 0;
el_row = nullptr;
css_height.predef(0);
}
table_row() {
min_height = 0;
top = 0;
bottom = 0;
border_bottom = 0;
border_top = 0;
height = 0;
el_row = nullptr;
css_height.predef(0);
}
table_row(int h, element::ptr& row)
{
min_height = 0;
height = h;
el_row = row;
border_bottom = 0;
border_top = 0;
top = 0;
bottom = 0;
if (row)
{
css_height = row->get_css_height();
}
}
table_row(int h, element::ptr& row) {
min_height = 0;
height = h;
el_row = row;
border_bottom = 0;
border_top = 0;
top = 0;
bottom = 0;
if (row) {
css_height = row->get_css_height();
}
}
table_row(const table_row& val)
{
min_height = val.min_height;
top = val.top;
bottom = val.bottom;
border_bottom = val.border_bottom;
border_top = val.border_top;
height = val.height;
css_height = val.css_height;
el_row = val.el_row;
}
table_row(const table_row& val) {
min_height = val.min_height;
top = val.top;
bottom = val.bottom;
border_bottom = val.border_bottom;
border_top = val.border_top;
height = val.height;
css_height = val.css_height;
el_row = val.el_row;
}
table_row(table_row&& val) noexcept
{
min_height = val.min_height;
top = val.top;
bottom = val.bottom;
border_bottom = val.border_bottom;
border_top = val.border_top;
height = val.height;
css_height = val.css_height;
el_row = std::move(val.el_row);
}
};
table_row(table_row&& val) noexcept {
min_height = val.min_height;
top = val.top;
bottom = val.bottom;
border_bottom = val.border_bottom;
border_top = val.border_top;
height = val.height;
css_height = val.css_height;
el_row = std::move(val.el_row);
}
};
struct table_column
{
typedef std::vector<table_column> vector;
struct table_column {
typedef std::vector<table_column> vector;
int min_width;
int max_width;
int width;
css_length css_width;
int border_left;
int border_right;
int left;
int right;
int min_width;
int max_width;
int width;
css_length css_width;
int border_left;
int border_right;
int left;
int right;
table_column()
{
left = 0;
right = 0;
border_left = 0;
border_right = 0;
min_width = 0;
max_width = 0;
width = 0;
css_width.predef(0);
}
table_column() {
left = 0;
right = 0;
border_left = 0;
border_right = 0;
min_width = 0;
max_width = 0;
width = 0;
css_width.predef(0);
}
table_column(int min_w, int max_w)
{
left = 0;
right = 0;
border_left = 0;
border_right = 0;
max_width = max_w;
min_width = min_w;
width = 0;
css_width.predef(0);
}
table_column(int min_w, int max_w) {
left = 0;
right = 0;
border_left = 0;
border_right = 0;
max_width = max_w;
min_width = min_w;
width = 0;
css_width.predef(0);
}
table_column(const table_column& val)
{
left = val.left;
right = val.right;
border_left = val.border_left;
border_right = val.border_right;
max_width = val.max_width;
min_width = val.min_width;
width = val.width;
css_width = val.css_width;
}
};
table_column(const table_column& val) {
left = val.left;
right = val.right;
border_left = val.border_left;
border_right = val.border_right;
max_width = val.max_width;
min_width = val.min_width;
width = val.width;
css_width = val.css_width;
}
};
class table_column_accessor
{
public:
virtual int& get(table_column& col) = 0;
class table_column_accessor {
public:
virtual int& get(table_column& col) = 0;
protected:
~table_column_accessor() = default;
};
protected:
~table_column_accessor() = default;
};
class table_column_accessor_max_width final : public table_column_accessor
{
public:
int& get(table_column& col) override;
};
class table_column_accessor_max_width final : public table_column_accessor {
public:
int& get(table_column& col) override;
};
class table_column_accessor_min_width final : public table_column_accessor
{
public:
int& get(table_column& col) override;
};
class table_column_accessor_min_width final : public table_column_accessor {
public:
int& get(table_column& col) override;
};
class table_column_accessor_width final : public table_column_accessor
{
public:
int& get(table_column& col) override;
};
class table_column_accessor_width final : public table_column_accessor {
public:
int& get(table_column& col) override;
};
struct table_cell
{
element::ptr el;
int colspan;
int rowspan;
int min_width;
int min_height;
int max_width;
int max_height;
int width;
int height;
margins borders;
struct table_cell {
element::ptr el;
int colspan;
int rowspan;
int min_width;
int min_height;
int max_width;
int max_height;
int width;
int height;
margins borders;
table_cell()
{
min_width = 0;
min_height = 0;
max_width = 0;
max_height = 0;
width = 0;
height = 0;
colspan = 1;
rowspan = 1;
el = nullptr;
}
table_cell() {
min_width = 0;
min_height = 0;
max_width = 0;
max_height = 0;
width = 0;
height = 0;
colspan = 1;
rowspan = 1;
el = nullptr;
}
table_cell(const table_cell& val)
{
el = val.el;
colspan = val.colspan;
rowspan = val.rowspan;
width = val.width;
height = val.height;
min_width = val.min_width;
min_height = val.min_height;
max_width = val.max_width;
max_height = val.max_height;
borders = val.borders;
}
table_cell(const table_cell& val) {
el = val.el;
colspan = val.colspan;
rowspan = val.rowspan;
width = val.width;
height = val.height;
min_width = val.min_width;
min_height = val.min_height;
max_width = val.max_width;
max_height = val.max_height;
borders = val.borders;
}
table_cell(table_cell&& val) noexcept
{
el = std::move(val.el);
colspan = val.colspan;
rowspan = val.rowspan;
width = val.width;
height = val.height;
min_width = val.min_width;
min_height = val.min_height;
max_width = val.max_width;
max_height = val.max_height;
borders = val.borders;
}
};
table_cell(table_cell&& val) noexcept {
el = std::move(val.el);
colspan = val.colspan;
rowspan = val.rowspan;
width = val.width;
height = val.height;
min_width = val.min_width;
min_height = val.min_height;
max_width = val.max_width;
max_height = val.max_height;
borders = val.borders;
}
};
class table_grid
{
public:
typedef std::vector< std::vector<table_cell> > rows;
private:
int m_rows_count;
int m_cols_count;
rows m_cells;
table_column::vector m_columns;
table_row::vector m_rows;
elements_vector m_captions;
int m_captions_height;
public:
class table_grid {
public:
typedef std::vector<std::vector<table_cell> > rows;
table_grid()
{
m_rows_count = 0;
m_cols_count = 0;
m_captions_height = 0;
}
private:
int m_rows_count;
int m_cols_count;
rows m_cells;
table_column::vector m_columns;
table_row::vector m_rows;
elements_vector m_captions;
int m_captions_height;
void clear();
void begin_row(element::ptr& row);
void add_cell(element::ptr& el);
bool is_rowspanned(int r, int c);
void finish();
table_cell* cell(int t_col, int t_row);
table_column& column(int c) { return m_columns[c]; }
table_row& row(int r) { return m_rows[r]; }
elements_vector& captions() { return m_captions; }
public:
table_grid() {
m_rows_count = 0;
m_cols_count = 0;
m_captions_height = 0;
}
int rows_count() const { return m_rows_count; }
int cols_count() const { return m_cols_count; }
void clear();
void begin_row(element::ptr& row);
void add_cell(element::ptr& el);
bool is_rowspanned(int r, int c);
void finish();
table_cell* cell(int t_col, int t_row);
table_column& column(int c) { return m_columns[c]; }
table_row& row(int r) { return m_rows[r]; }
elements_vector& captions() { return m_captions; }
void captions_height(int height) { m_captions_height = height; }
int captions_height() const { return m_captions_height; }
int rows_count() const { return m_rows_count; }
int cols_count() const { return m_cols_count; }
void distribute_max_width(int width, int start, int end);
void distribute_min_width(int width, int start, int end);
void distribute_width(int width, int start, int end);
void distribute_width(int width, int start, int end, table_column_accessor* acc);
int calc_table_width(int block_width, bool is_auto, int& min_table_width, int& max_table_width);
void calc_horizontal_positions(margins& table_borders, border_collapse bc, int bdr_space_x);
void calc_vertical_positions(margins& table_borders, border_collapse bc, int bdr_space_y);
void calc_rows_height(int blockHeight, int borderSpacingY);
};
}
void captions_height(int height) { m_captions_height = height; }
int captions_height() const { return m_captions_height; }
void distribute_max_width(int width, int start, int end);
void distribute_min_width(int width, int start, int end);
void distribute_width(int width, int start, int end);
void distribute_width(int width, int start, int end, table_column_accessor* acc);
int calc_table_width(int block_width, bool is_auto, int& min_table_width, int& max_table_width);
void calc_horizontal_positions(margins& table_borders, border_collapse bc, int bdr_space_x);
void calc_vertical_positions(margins& table_borders, border_collapse bc, int bdr_space_y);
void calc_rows_height(int blockHeight, int borderSpacingY);
};
} // namespace litehtml
#endif // LH_TABLE_H

View file

@ -46,91 +46,58 @@ namespace litehtml {
// (e.g., via a using statement).
class tstring_view {
public:
using value_type = tchar_t;
public:
using value_type = tchar_t;
using pointer = tchar_t*;
using pointer = tchar_t*;
using const_pointer = const tchar_t*;
using const_pointer = const tchar_t*;
using reference = tchar_t&;
using reference = tchar_t&;
using const_reference = const tchar_t&;
using const_reference = const tchar_t&;
using iterator = const_pointer;
using iterator = const_pointer;
using const_iterator = const_pointer;
using const_iterator = const_pointer;
using size_type = size_t;
using size_type = size_t;
using difference_type = std::ptrdiff_t;
using difference_type = std::ptrdiff_t;
public:
tstring_view() = default;
public:
tstring_view() = default;
tstring_view(const tstring_view& other) = default;
tstring_view(const tstring_view& other) = default;
tstring_view(const_pointer s, size_type size)
: data_(s)
, size_(size)
{
}
tstring_view(const_pointer s, size_type size) : data_(s), size_(size) {}
constexpr const_iterator begin() const
{
return data_;
}
constexpr const_iterator begin() const { return data_; }
constexpr const_iterator cbegin() const
{
return data_;
}
constexpr const_iterator cbegin() const { return data_; }
constexpr const_iterator end() const
{
return data_ + size_;
}
constexpr const_iterator end() const { return data_ + size_; }
constexpr const_iterator cend() const
{
return data_ + size_;
}
constexpr const_iterator cend() const { return data_ + size_; }
constexpr const_reference operator[](size_type offset) const
{
return *(data_ + offset);
}
constexpr const_reference operator[](size_type offset) const { return *(data_ + offset); }
constexpr const_pointer data() const
{
return data_;
}
constexpr const_pointer data() const { return data_; }
size_type size() const
{
return size_;
}
size_type size() const { return size_; }
size_type length() const
{
return size_;
}
size_type length() const { return size_; }
bool empty() const
{
return (size_ == 0);
}
bool empty() const { return (size_ == 0); }
private:
const_pointer data_ = nullptr;
private:
const_pointer data_ = nullptr;
size_type size_ = 0;
size_type size_ = 0;
};
std::basic_ostream<tstring_view::value_type>& operator<<(
std::basic_ostream<tstring_view::value_type>&,
tstring_view str);
std::basic_ostream<tstring_view::value_type>& operator<<(std::basic_ostream<tstring_view::value_type>&, tstring_view str);
} // namespace litehtml
} // namespace litehtml
#endif // LITEHTML_TSTRING_VIEW_H__
#endif // LITEHTML_TSTRING_VIEW_H__

File diff suppressed because it is too large Load diff

View file

@ -39,92 +39,55 @@
namespace litehtml {
class url {
public:
url() = default;
public:
url() = default;
explicit url(const tstring& str);
explicit url(const tstring& str);
url(const tstring& scheme,
const tstring& authority,
const tstring& path,
const tstring& query,
const tstring& fragment);
url(const tstring& scheme, const tstring& authority, const tstring& path, const tstring& query, const tstring& fragment);
const tstring& string() const
{
return str_;
}
const tstring& string() const { return str_; }
const tstring& scheme() const
{
return scheme_;
}
const tstring& scheme() const { return scheme_; }
bool has_scheme() const
{
return !scheme_.empty();
}
bool has_scheme() const { return !scheme_.empty(); }
const tstring& authority() const
{
return authority_;
}
const tstring& authority() const { return authority_; }
bool has_authority() const
{
return !authority_.empty();
}
bool has_authority() const { return !authority_.empty(); }
const tstring& path() const
{
return path_;
}
const tstring& path() const { return path_; }
bool has_path() const
{
return !path_.empty();
}
bool has_path() const { return !path_.empty(); }
const tstring& query() const
{
return query_;
}
const tstring& query() const { return query_; }
bool has_query() const
{
return !query_.empty();
}
bool has_query() const { return !query_.empty(); }
const tstring& fragment() const
{
return fragment_;
}
const tstring& fragment() const { return fragment_; }
bool has_fragment() const
{
return !fragment_.empty();
}
bool has_fragment() const { return !fragment_.empty(); }
protected:
tstring str_;
protected:
tstring str_;
// Assume URLs are relative by default. See RFC 3986 Section 4.3 for
// information on which URLs are considered relative and which URLs are
// considered absolute:
//
// https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
// Assume URLs are relative by default. See RFC 3986 Section 4.3 for
// information on which URLs are considered relative and which URLs are
// considered absolute:
//
// https://datatracker.ietf.org/doc/html/rfc3986#section-4.3
bool absolute_ = false;
bool absolute_ = false;
tstring scheme_;
tstring scheme_;
tstring authority_;
tstring authority_;
tstring path_;
tstring path_;
tstring query_;
tstring query_;
tstring fragment_;
tstring fragment_;
};
// Returns a URL that is resolved from the reference URL that might be
@ -134,6 +97,6 @@ protected:
url resolve(const url& base, const url& reference);
} // namespace litehtml
} // namespace litehtml
#endif // LITEHTML_URL_H__
#endif // LITEHTML_URL_H__

View file

@ -46,6 +46,6 @@ tstring url_path_append(const tstring& base, const tstring& path);
tstring url_path_resolve(const tstring& base, const tstring& path);
} // namespace litehtml
} // namespace litehtml
#endif // LITEHTML_URL_PATH_H__
#endif // LITEHTML_URL_PATH_H__

View file

@ -4,56 +4,43 @@
#include "os_types.h"
#include "types.h"
namespace litehtml
{
class utf8_to_wchar
{
const byte* m_utf8;
std::wstring m_str;
public:
utf8_to_wchar(const char* val);
operator const wchar_t*() const
{
return m_str.c_str();
}
private:
ucode_t getb()
{
if (!(*m_utf8)) return 0;
return *m_utf8++;
}
ucode_t get_next_utf8(ucode_t val)
{
return (val & 0x3f);
}
ucode_t get_char();
};
namespace litehtml {
class utf8_to_wchar {
const byte* m_utf8;
std::wstring m_str;
class wchar_to_utf8
{
std::string m_str;
public:
wchar_to_utf8(const std::wstring& val);
operator const char*() const
{
return m_str.c_str();
}
public:
utf8_to_wchar(const char* val);
operator const wchar_t*() const { return m_str.c_str(); }
const char* c_str() const
{
return m_str.c_str();
}
};
private:
ucode_t getb() {
if (!(*m_utf8)) return 0;
return *m_utf8++;
}
ucode_t get_next_utf8(ucode_t val) { return (val & 0x3f); }
ucode_t get_char();
};
class wchar_to_utf8 {
std::string m_str;
public:
wchar_to_utf8(const std::wstring& val);
operator const char*() const { return m_str.c_str(); }
const char* c_str() const { return m_str.c_str(); }
};
#ifdef LITEHTML_UTF8
#define litehtml_from_utf8(str) str
#define litehtml_to_utf8(str) str
#define litehtml_from_wchar(str) litehtml::wchar_to_utf8(str)
#define litehtml_from_utf8(str) str
#define litehtml_to_utf8(str) str
#define litehtml_from_wchar(str) litehtml::wchar_to_utf8(str)
#else
#define litehtml_from_utf8(str) litehtml::utf8_to_wchar(str)
#define litehtml_from_wchar(str) str
#define litehtml_to_utf8(str) litehtml::wchar_to_utf8(str)
#define litehtml_from_utf8(str) litehtml::utf8_to_wchar(str)
#define litehtml_from_wchar(str) str
#define litehtml_to_utf8(str) litehtml::wchar_to_utf8(str)
#endif
}
} // namespace litehtml
#endif // LH_UTF8_STRINGS_H

View file

@ -1,61 +1,54 @@
#ifndef LH_WEB_COLOR_H
#define LH_WEB_COLOR_H
namespace litehtml
{
struct def_color
{
const tchar_t* name;
const tchar_t* rgb;
};
namespace litehtml {
struct def_color {
const tchar_t* name;
const tchar_t* rgb;
};
extern def_color g_def_colors[];
extern def_color g_def_colors[];
class document_container;
class document_container;
struct web_color
{
byte blue;
byte green;
byte red;
byte alpha;
struct web_color {
byte blue;
byte green;
byte red;
byte alpha;
web_color(byte r, byte g, byte b, byte a = 255)
{
blue = b;
green = g;
red = r;
alpha = a;
}
web_color(byte r, byte g, byte b, byte a = 255) {
blue = b;
green = g;
red = r;
alpha = a;
}
web_color()
{
blue = 0;
green = 0;
red = 0;
alpha = 0xFF;
}
web_color() {
blue = 0;
green = 0;
red = 0;
alpha = 0xFF;
}
web_color(const web_color& val)
{
blue = val.blue;
green = val.green;
red = val.red;
alpha = val.alpha;
}
web_color(const web_color& val) {
blue = val.blue;
green = val.green;
red = val.red;
alpha = val.alpha;
}
web_color& operator=(const web_color& val)
{
blue = val.blue;
green = val.green;
red = val.red;
alpha = val.alpha;
return *this;
}
static web_color from_string(const tchar_t* str, litehtml::document_container* callback);
static litehtml::tstring resolve_name(const tchar_t* name, litehtml::document_container* callback);
static bool is_color(const tchar_t* str);
};
}
web_color& operator=(const web_color& val) {
blue = val.blue;
green = val.green;
red = val.red;
alpha = val.alpha;
return *this;
}
static web_color from_string(const tchar_t* str, litehtml::document_container* callback);
static litehtml::tstring resolve_name(const tchar_t* name, litehtml::document_container* callback);
static bool is_color(const tchar_t* str);
};
} // namespace litehtml
#endif // LH_WEB_COLOR_H

View file

@ -1,76 +1,70 @@
#include "html.h"
#include "background.h"
litehtml::background::background()
{
m_attachment = background_attachment_scroll;
m_repeat = background_repeat_repeat;
m_clip = background_box_border;
m_origin = background_box_padding;
m_color.alpha = 0;
m_color.red = 0;
m_color.green = 0;
m_color.blue = 0;
#include "html.h"
litehtml::background::background() {
m_attachment = background_attachment_scroll;
m_repeat = background_repeat_repeat;
m_clip = background_box_border;
m_origin = background_box_padding;
m_color.alpha = 0;
m_color.red = 0;
m_color.green = 0;
m_color.blue = 0;
}
litehtml::background::background( const background& val )
{
m_image = val.m_image;
m_baseurl = val.m_baseurl;
m_color = val.m_color;
m_attachment = val.m_attachment;
m_position = val.m_position;
m_repeat = val.m_repeat;
m_clip = val.m_clip;
m_origin = val.m_origin;
litehtml::background::background(const background& val) {
m_image = val.m_image;
m_baseurl = val.m_baseurl;
m_color = val.m_color;
m_attachment = val.m_attachment;
m_position = val.m_position;
m_repeat = val.m_repeat;
m_clip = val.m_clip;
m_origin = val.m_origin;
}
litehtml::background& litehtml::background::operator=( const background& val )
{
m_image = val.m_image;
m_baseurl = val.m_baseurl;
m_color = val.m_color;
m_attachment = val.m_attachment;
m_position = val.m_position;
m_repeat = val.m_repeat;
m_clip = val.m_clip;
m_origin = val.m_origin;
return *this;
litehtml::background& litehtml::background::operator=(const background& val) {
m_image = val.m_image;
m_baseurl = val.m_baseurl;
m_color = val.m_color;
m_attachment = val.m_attachment;
m_position = val.m_position;
m_repeat = val.m_repeat;
m_clip = val.m_clip;
m_origin = val.m_origin;
return *this;
}
litehtml::background_paint::background_paint() : color(0, 0, 0, 0)
{
position_x = 0;
position_y = 0;
attachment = background_attachment_scroll;
repeat = background_repeat_repeat;
is_root = false;
litehtml::background_paint::background_paint() : color(0, 0, 0, 0) {
position_x = 0;
position_y = 0;
attachment = background_attachment_scroll;
repeat = background_repeat_repeat;
is_root = false;
}
litehtml::background_paint::background_paint( const background_paint& val )
{
image = val.image;
baseurl = val.baseurl;
attachment = val.attachment;
repeat = val.repeat;
color = val.color;
clip_box = val.clip_box;
origin_box = val.origin_box;
border_box = val.border_box;
border_radius = val.border_radius;
image_size = val.image_size;
position_x = val.position_x;
position_y = val.position_y;
is_root = val.is_root;
litehtml::background_paint::background_paint(const background_paint& val) {
image = val.image;
baseurl = val.baseurl;
attachment = val.attachment;
repeat = val.repeat;
color = val.color;
clip_box = val.clip_box;
origin_box = val.origin_box;
border_box = val.border_box;
border_radius = val.border_radius;
image_size = val.image_size;
position_x = val.position_x;
position_y = val.position_y;
is_root = val.is_root;
}
litehtml::background_paint& litehtml::background_paint::operator=( const background& val )
{
attachment = val.m_attachment;
baseurl = val.m_baseurl;
image = val.m_image;
repeat = val.m_repeat;
color = val.m_color;
return *this;
litehtml::background_paint& litehtml::background_paint::operator=(const background& val) {
attachment = val.m_attachment;
baseurl = val.m_baseurl;
image = val.m_image;
repeat = val.m_repeat;
color = val.m_color;
return *this;
}

View file

@ -1,432 +1,331 @@
#include "html.h"
#include "box.h"
#include "html.h"
#include "html_tag.h"
litehtml::box_type litehtml::block_box::get_type() const { return box_block; }
litehtml::box_type litehtml::block_box::get_type() const
{
return box_block;
int litehtml::block_box::height() const { return m_element->height(); }
int litehtml::block_box::width() const { return m_element->width(); }
void litehtml::block_box::add_element(const element::ptr& el) {
m_element = el;
el->m_box = this;
}
int litehtml::block_box::height() const
{
return m_element->height();
void litehtml::block_box::finish(bool last_box) {
if (!m_element) return;
m_element->apply_relative_shift(m_box_right - m_box_left);
}
int litehtml::block_box::width() const
{
return m_element->width();
bool litehtml::block_box::can_hold(const element::ptr& el, white_space ws) const {
if (m_element || el->is_inline_box()) {
return false;
}
return true;
}
void litehtml::block_box::add_element(const element::ptr &el)
{
m_element = el;
el->m_box = this;
bool litehtml::block_box::is_empty() const {
if (m_element) {
return false;
}
return true;
}
void litehtml::block_box::finish(bool last_box)
{
if(!m_element) return;
m_element->apply_relative_shift(m_box_right - m_box_left);
int litehtml::block_box::baseline() const {
if (m_element) {
return m_element->get_base_line();
}
return 0;
}
bool litehtml::block_box::can_hold(const element::ptr &el, white_space ws) const
{
if(m_element || el->is_inline_box())
{
return false;
}
return true;
void litehtml::block_box::get_elements(elements_vector& els) { els.push_back(m_element); }
int litehtml::block_box::top_margin() const {
if (m_element && m_element->collapse_top_margin()) {
return m_element->m_margins.top;
}
return 0;
}
bool litehtml::block_box::is_empty() const
{
if(m_element)
{
return false;
}
return true;
int litehtml::block_box::bottom_margin() const {
if (m_element && m_element->collapse_bottom_margin()) {
return m_element->m_margins.bottom;
}
return 0;
}
int litehtml::block_box::baseline() const
{
if(m_element)
{
return m_element->get_base_line();
}
return 0;
void litehtml::block_box::y_shift(int shift) {
m_box_top += shift;
if (m_element) {
m_element->m_pos.y += shift;
}
}
void litehtml::block_box::get_elements( elements_vector& els )
{
els.push_back(m_element);
}
int litehtml::block_box::top_margin() const
{
if(m_element && m_element->collapse_top_margin())
{
return m_element->m_margins.top;
}
return 0;
}
int litehtml::block_box::bottom_margin() const
{
if(m_element && m_element->collapse_bottom_margin())
{
return m_element->m_margins.bottom;
}
return 0;
}
void litehtml::block_box::y_shift( int shift )
{
m_box_top += shift;
if(m_element)
{
m_element->m_pos.y += shift;
}
}
void litehtml::block_box::new_width( int left, int right, elements_vector& els )
{
}
void litehtml::block_box::new_width(int left, int right, elements_vector& els) {}
//////////////////////////////////////////////////////////////////////////
litehtml::box_type litehtml::line_box::get_type() const
{
return box_line;
litehtml::box_type litehtml::line_box::get_type() const { return box_line; }
int litehtml::line_box::height() const { return m_height; }
int litehtml::line_box::width() const { return m_width; }
void litehtml::line_box::add_element(const element::ptr& el) {
el->m_skip = false;
el->m_box = nullptr;
bool add = true;
if ((m_items.empty() && el->is_white_space()) || el->is_break()) {
el->m_skip = true;
} else if (el->is_white_space()) {
if (have_last_space()) {
add = false;
el->m_skip = true;
}
}
if (add) {
el->m_box = this;
m_items.push_back(el);
if (!el->m_skip) {
int el_shift_left = el->get_inline_shift_left();
int el_shift_right = el->get_inline_shift_right();
el->m_pos.x = m_box_left + m_width + el_shift_left + el->content_margins_left();
el->m_pos.y = m_box_top + el->content_margins_top();
m_width += el->width() + el_shift_left + el_shift_right;
}
}
}
int litehtml::line_box::height() const
{
return m_height;
void litehtml::line_box::finish(bool last_box) {
if (is_empty() || (!is_empty() && last_box && is_break_only())) {
m_height = 0;
return;
}
for (auto i = m_items.rbegin(); i != m_items.rend(); i++) {
if ((*i)->is_white_space() || (*i)->is_break()) {
if (!(*i)->m_skip) {
(*i)->m_skip = true;
m_width -= (*i)->width();
}
} else {
break;
}
}
int base_line = m_font_metrics.base_line();
int line_height = m_line_height;
int add_x = 0;
switch (m_text_align) {
case text_align_right:
if (m_width < (m_box_right - m_box_left)) {
add_x = (m_box_right - m_box_left) - m_width;
}
break;
case text_align_center:
if (m_width < (m_box_right - m_box_left)) {
add_x = ((m_box_right - m_box_left) - m_width) / 2;
}
break;
default:
add_x = 0;
}
m_height = 0;
// find line box baseline and line-height
for (const auto& el : m_items) {
if (el->get_display() == display_inline_text) {
font_metrics fm;
el->get_font(&fm);
base_line = std::max(base_line, fm.base_line());
line_height = std::max(line_height, el->line_height());
m_height = std::max(m_height, fm.height);
}
el->m_pos.x += add_x;
}
if (m_height) {
base_line += (line_height - m_height) / 2;
}
m_height = line_height;
int y1 = 0;
int y2 = m_height;
for (const auto& el : m_items) {
if (el->get_display() == display_inline_text) {
font_metrics fm;
el->get_font(&fm);
el->m_pos.y = m_height - base_line - fm.ascent;
} else {
switch (el->get_vertical_align()) {
case va_super:
case va_sub:
case va_baseline:
el->m_pos.y = m_height - base_line - el->height() + el->get_base_line() + el->content_margins_top();
break;
case va_top:
el->m_pos.y = y1 + el->content_margins_top();
break;
case va_text_top:
el->m_pos.y = m_height - base_line - m_font_metrics.ascent + el->content_margins_top();
break;
case va_middle:
el->m_pos.y = m_height - base_line - m_font_metrics.x_height / 2 - el->height() / 2 + el->content_margins_top();
break;
case va_bottom:
el->m_pos.y = y2 - el->height() + el->content_margins_top();
break;
case va_text_bottom:
el->m_pos.y = m_height - base_line + m_font_metrics.descent - el->height() + el->content_margins_top();
break;
}
y1 = std::min(y1, el->top());
y2 = std::max(y2, el->bottom());
}
}
for (const auto& el : m_items) {
el->m_pos.y -= y1;
el->m_pos.y += m_box_top;
if (el->get_display() != display_inline_text) {
switch (el->get_vertical_align()) {
case va_top:
el->m_pos.y = m_box_top + el->content_margins_top();
break;
case va_bottom:
el->m_pos.y = m_box_top + (y2 - y1) - el->height() + el->content_margins_top();
break;
case va_baseline:
// TODO: process vertical align "baseline"
break;
case va_middle:
// TODO: process vertical align "middle"
break;
case va_sub:
// TODO: process vertical align "sub"
break;
case va_super:
// TODO: process vertical align "super"
break;
case va_text_bottom:
// TODO: process vertical align "text-bottom"
break;
case va_text_top:
// TODO: process vertical align "text-top"
break;
}
}
el->apply_relative_shift(m_box_right - m_box_left);
}
m_height = y2 - y1;
m_baseline = (base_line - y1) - (m_height - line_height);
}
int litehtml::line_box::width() const
{
return m_width;
bool litehtml::line_box::can_hold(const element::ptr& el, white_space ws) const {
if (!el->is_inline_box()) return false;
if (el->is_break()) {
return false;
}
if (ws == white_space_nowrap || ws == white_space_pre) {
return true;
}
if (m_box_left + m_width + el->width() + el->get_inline_shift_left() + el->get_inline_shift_right() > m_box_right) {
return false;
}
return true;
}
void litehtml::line_box::add_element(const element::ptr &el)
{
el->m_skip = false;
el->m_box = nullptr;
bool add = true;
if( (m_items.empty() && el->is_white_space()) || el->is_break() )
{
el->m_skip = true;
} else if(el->is_white_space())
{
if (have_last_space())
{
add = false;
el->m_skip = true;
}
}
if(add)
{
el->m_box = this;
m_items.push_back(el);
if(!el->m_skip)
{
int el_shift_left = el->get_inline_shift_left();
int el_shift_right = el->get_inline_shift_right();
el->m_pos.x = m_box_left + m_width + el_shift_left + el->content_margins_left();
el->m_pos.y = m_box_top + el->content_margins_top();
m_width += el->width() + el_shift_left + el_shift_right;
}
}
bool litehtml::line_box::have_last_space() const {
bool ret = false;
for (auto i = m_items.rbegin(); i != m_items.rend() && !ret; i++) {
if ((*i)->is_white_space() || (*i)->is_break()) {
ret = true;
} else {
break;
}
}
return ret;
}
void litehtml::line_box::finish(bool last_box)
{
if( is_empty() || (!is_empty() && last_box && is_break_only()) )
{
m_height = 0;
return;
}
for(auto i = m_items.rbegin(); i != m_items.rend(); i++)
{
if((*i)->is_white_space() || (*i)->is_break())
{
if(!(*i)->m_skip)
{
(*i)->m_skip = true;
m_width -= (*i)->width();
}
} else
{
break;
}
}
int base_line = m_font_metrics.base_line();
int line_height = m_line_height;
int add_x = 0;
switch(m_text_align)
{
case text_align_right:
if(m_width < (m_box_right - m_box_left))
{
add_x = (m_box_right - m_box_left) - m_width;
}
break;
case text_align_center:
if(m_width < (m_box_right - m_box_left))
{
add_x = ((m_box_right - m_box_left) - m_width) / 2;
}
break;
default:
add_x = 0;
}
m_height = 0;
// find line box baseline and line-height
for(const auto& el : m_items)
{
if(el->get_display() == display_inline_text)
{
font_metrics fm;
el->get_font(&fm);
base_line = std::max(base_line, fm.base_line());
line_height = std::max(line_height, el->line_height());
m_height = std::max(m_height, fm.height);
}
el->m_pos.x += add_x;
}
if(m_height)
{
base_line += (line_height - m_height) / 2;
}
m_height = line_height;
int y1 = 0;
int y2 = m_height;
for (const auto& el : m_items)
{
if(el->get_display() == display_inline_text)
{
font_metrics fm;
el->get_font(&fm);
el->m_pos.y = m_height - base_line - fm.ascent;
} else
{
switch(el->get_vertical_align())
{
case va_super:
case va_sub:
case va_baseline:
el->m_pos.y = m_height - base_line - el->height() + el->get_base_line() + el->content_margins_top();
break;
case va_top:
el->m_pos.y = y1 + el->content_margins_top();
break;
case va_text_top:
el->m_pos.y = m_height - base_line - m_font_metrics.ascent + el->content_margins_top();
break;
case va_middle:
el->m_pos.y = m_height - base_line - m_font_metrics.x_height / 2 - el->height() / 2 + el->content_margins_top();
break;
case va_bottom:
el->m_pos.y = y2 - el->height() + el->content_margins_top();
break;
case va_text_bottom:
el->m_pos.y = m_height - base_line + m_font_metrics.descent - el->height() + el->content_margins_top();
break;
}
y1 = std::min(y1, el->top());
y2 = std::max(y2, el->bottom());
}
}
for (const auto& el : m_items)
{
el->m_pos.y -= y1;
el->m_pos.y += m_box_top;
if(el->get_display() != display_inline_text)
{
switch(el->get_vertical_align())
{
case va_top:
el->m_pos.y = m_box_top + el->content_margins_top();
break;
case va_bottom:
el->m_pos.y = m_box_top + (y2 - y1) - el->height() + el->content_margins_top();
break;
case va_baseline:
//TODO: process vertical align "baseline"
break;
case va_middle:
//TODO: process vertical align "middle"
break;
case va_sub:
//TODO: process vertical align "sub"
break;
case va_super:
//TODO: process vertical align "super"
break;
case va_text_bottom:
//TODO: process vertical align "text-bottom"
break;
case va_text_top:
//TODO: process vertical align "text-top"
break;
}
}
el->apply_relative_shift(m_box_right - m_box_left);
}
m_height = y2 - y1;
m_baseline = (base_line - y1) - (m_height - line_height);
bool litehtml::line_box::is_empty() const {
if (m_items.empty()) return true;
for (auto i = m_items.rbegin(); i != m_items.rend(); i++) {
if (!(*i)->m_skip || (*i)->is_break()) {
return false;
}
}
return true;
}
bool litehtml::line_box::can_hold(const element::ptr &el, white_space ws) const
{
if(!el->is_inline_box()) return false;
int litehtml::line_box::baseline() const { return m_baseline; }
if(el->is_break())
{
return false;
}
void litehtml::line_box::get_elements(elements_vector& els) { els.insert(els.begin(), m_items.begin(), m_items.end()); }
if(ws == white_space_nowrap || ws == white_space_pre)
{
return true;
}
int litehtml::line_box::top_margin() const { return 0; }
if(m_box_left + m_width + el->width() + el->get_inline_shift_left() + el->get_inline_shift_right() > m_box_right)
{
return false;
}
int litehtml::line_box::bottom_margin() const { return 0; }
return true;
void litehtml::line_box::y_shift(int shift) {
m_box_top += shift;
for (auto& el : m_items) {
el->m_pos.y += shift;
}
}
bool litehtml::line_box::have_last_space() const
{
bool ret = false;
for (auto i = m_items.rbegin(); i != m_items.rend() && !ret; i++)
{
if((*i)->is_white_space() || (*i)->is_break())
{
ret = true;
} else
{
break;
}
}
return ret;
bool litehtml::line_box::is_break_only() const {
if (m_items.empty()) return true;
if (m_items.front()->is_break()) {
for (auto& el : m_items) {
if (!el->m_skip) {
return false;
}
}
return true;
}
return false;
}
bool litehtml::line_box::is_empty() const
{
if(m_items.empty()) return true;
for (auto i = m_items.rbegin(); i != m_items.rend(); i++)
{
if(!(*i)->m_skip || (*i)->is_break())
{
return false;
}
}
return true;
void litehtml::line_box::new_width(int left, int right, elements_vector& els) {
int add = left - m_box_left;
if (add) {
m_box_left = left;
m_box_right = right;
m_width = 0;
auto remove_begin = m_items.end();
for (auto i = m_items.begin() + 1; i != m_items.end(); i++) {
element::ptr el = (*i);
if (!el->m_skip) {
if (m_box_left + m_width + el->width() + el->get_inline_shift_right() + el->get_inline_shift_left() > m_box_right) {
remove_begin = i;
break;
} else {
el->m_pos.x += add;
m_width += el->width() + el->get_inline_shift_right() + el->get_inline_shift_left();
}
}
}
if (remove_begin != m_items.end()) {
els.insert(els.begin(), remove_begin, m_items.end());
m_items.erase(remove_begin, m_items.end());
for (const auto& el : els) {
el->m_box = nullptr;
}
}
}
}
int litehtml::line_box::baseline() const
{
return m_baseline;
}
void litehtml::line_box::get_elements( elements_vector& els )
{
els.insert(els.begin(), m_items.begin(), m_items.end());
}
int litehtml::line_box::top_margin() const
{
return 0;
}
int litehtml::line_box::bottom_margin() const
{
return 0;
}
void litehtml::line_box::y_shift( int shift )
{
m_box_top += shift;
for (auto& el : m_items)
{
el->m_pos.y += shift;
}
}
bool litehtml::line_box::is_break_only() const
{
if(m_items.empty()) return true;
if(m_items.front()->is_break())
{
for (auto& el : m_items)
{
if(!el->m_skip)
{
return false;
}
}
return true;
}
return false;
}
void litehtml::line_box::new_width( int left, int right, elements_vector& els )
{
int add = left - m_box_left;
if(add)
{
m_box_left = left;
m_box_right = right;
m_width = 0;
auto remove_begin = m_items.end();
for (auto i = m_items.begin() + 1; i != m_items.end(); i++)
{
element::ptr el = (*i);
if(!el->m_skip)
{
if(m_box_left + m_width + el->width() + el->get_inline_shift_right() + el->get_inline_shift_left() > m_box_right)
{
remove_begin = i;
break;
} else
{
el->m_pos.x += add;
m_width += el->width() + el->get_inline_shift_right() + el->get_inline_shift_left();
}
}
}
if(remove_begin != m_items.end())
{
els.insert(els.begin(), remove_begin, m_items.end());
m_items.erase(remove_begin, m_items.end());
for(const auto& el : els)
{
el->m_box = nullptr;
}
}
}
}

View file

@ -33,50 +33,37 @@
namespace {
bool lookup(const uint32_t* table, litehtml::tchar_t c)
{
return table[c >> 5] & (1 << (c & 0x1f));
}
bool lookup(const uint32_t* table, litehtml::tchar_t c) { return table[c >> 5] & (1 << (c & 0x1f)); }
} // namespace
} // namespace
namespace litehtml {
bool is_ascii_codepoint(litehtml::tchar_t c)
{
return (c < 128);
}
bool is_ascii_codepoint(litehtml::tchar_t c) { return (c < 128); }
// https://datatracker.ietf.org/doc/html/rfc3986#section-2.2
bool is_url_reserved_codepoint(litehtml::tchar_t c)
{
static const uint32_t reserved_lookup[] = {
0x00000000,
0xac009fda,
0x28000001,
0x00000000
};
bool is_url_reserved_codepoint(litehtml::tchar_t c) {
static const uint32_t reserved_lookup[] = {0x00000000, 0xac009fda, 0x28000001, 0x00000000};
if (!is_ascii_codepoint(c)) {
return false;
}
return lookup(reserved_lookup, c);
if (!is_ascii_codepoint(c)) {
return false;
}
return lookup(reserved_lookup, c);
}
// https://datatracker.ietf.org/doc/html/rfc3986#section-3.1
bool is_url_scheme_codepoint(litehtml::tchar_t c)
{
static const uint32_t scheme_lookup[] = {
0x00000000,
0x03ff6800,
0x07fffffe,
0x07fffffe,
};
bool is_url_scheme_codepoint(litehtml::tchar_t c) {
static const uint32_t scheme_lookup[] = {
0x00000000,
0x03ff6800,
0x07fffffe,
0x07fffffe,
};
if (!is_ascii_codepoint(c)) {
return false;
}
return lookup(scheme_lookup, c);
if (!is_ascii_codepoint(c)) {
return false;
}
return lookup(scheme_lookup, c);
}
} // namespace litehtml
} // namespace litehtml

View file

@ -1,12 +1,11 @@
#include "html.h"
#include "context.h"
#include "html.h"
#include "stylesheet.h"
void litehtml::context::load_master_stylesheet(const tchar_t* str) {
media_query_list::ptr media;
void litehtml::context::load_master_stylesheet( const tchar_t* str )
{
media_query_list::ptr media;
m_master_css.parse_stylesheet(str, nullptr, std::shared_ptr<litehtml::document>(), media_query_list::ptr());
m_master_css.sort_selectors();
m_master_css.parse_stylesheet(str, nullptr, std::shared_ptr<litehtml::document>(), media_query_list::ptr());
m_master_css.sort_selectors();
}

View file

@ -1,54 +1,44 @@
#include "html.h"
#include "css_length.h"
void litehtml::css_length::fromString( const tstring& str, const tstring& predefs, int defValue )
{
// TODO: Make support for calc
if(str.substr(0, 4) == _t("calc"))
{
m_is_predefined = true;
m_predef = 0;
return;
}
#include "html.h"
int predef = value_index(str, predefs, -1);
if(predef >= 0)
{
m_is_predefined = true;
m_predef = predef;
} else
{
m_is_predefined = false;
void litehtml::css_length::fromString(const tstring& str, const tstring& predefs, int defValue) {
// TODO: Make support for calc
if (str.substr(0, 4) == _t("calc")) {
m_is_predefined = true;
m_predef = 0;
return;
}
tstring num;
tstring un;
bool is_unit = false;
for(tchar_t chr : str)
{
if(!is_unit)
{
if(t_isdigit(chr) || chr == _t('.') || chr == _t('+') || chr == _t('-'))
{
num += chr;
} else
{
is_unit = true;
}
}
if(is_unit)
{
un += chr;
}
}
if(!num.empty())
{
m_value = (float) t_strtod(num.c_str(), nullptr);
m_units = (css_units) value_index(un, css_units_strings, css_units_none);
} else
{
// not a number so it is predefined
m_is_predefined = true;
m_predef = defValue;
}
}
int predef = value_index(str, predefs, -1);
if (predef >= 0) {
m_is_predefined = true;
m_predef = predef;
} else {
m_is_predefined = false;
tstring num;
tstring un;
bool is_unit = false;
for (tchar_t chr : str) {
if (!is_unit) {
if (t_isdigit(chr) || chr == _t('.') || chr == _t('+') || chr == _t('-')) {
num += chr;
} else {
is_unit = true;
}
}
if (is_unit) {
un += chr;
}
}
if (!num.empty()) {
m_value = (float)t_strtod(num.c_str(), nullptr);
m_units = (css_units)value_index(un, css_units_strings, css_units_none);
} else {
// not a number so it is predefined
m_is_predefined = true;
m_predef = defValue;
}
}
}

Some files were not shown because too many files have changed in this diff Show more