Composition and decomposition text controls are multiline now + they synchronize text selection.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
<ClCompile Include="..\src\compose.cpp" />
|
||||
<ClCompile Include="..\src\data.cpp" />
|
||||
<ClCompile Include="..\src\decompose.cpp" />
|
||||
<ClCompile Include="..\src\mapping.cpp" />
|
||||
<ClCompile Include="..\src\stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<ClCompile Include="..\src\data.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\mapping.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\stdafx.h">
|
||||
|
||||
@@ -19,22 +19,59 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
///
|
||||
/// Public function calling convention
|
||||
///
|
||||
#ifdef LIBZRCOLA
|
||||
#define ZRCOLA_API __declspec(dllexport)
|
||||
#define ZRCOLA_API __declspec(dllexport)
|
||||
#else
|
||||
#define ZRCOLA_API __declspec(dllimport)
|
||||
#define ZRCOLA_API __declspec(dllimport)
|
||||
#endif
|
||||
#define ZRCOLA_NOVTABLE __declspec(novtable)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4251)
|
||||
|
||||
|
||||
namespace ZRCola {
|
||||
///
|
||||
/// Source-destination index mapping
|
||||
/// Composed-decomposed index transformation mapping
|
||||
///
|
||||
class mapping {
|
||||
class ZRCOLA_NOVTABLE mapping {
|
||||
public:
|
||||
size_t src; ///< Source index
|
||||
size_t dst; ///< Destination index
|
||||
size_t cmp; ///< Character index in composed string
|
||||
size_t decmp; ///< Character index in decomposed string
|
||||
|
||||
inline mapping() {};
|
||||
inline mapping(size_t s, size_t d) : src(s), dst(d) {}
|
||||
inline mapping(_In_ size_t c, _In_ size_t d) : cmp(c), decmp(d) {}
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// A vector for composed-decomposed index transformation mapping
|
||||
///
|
||||
class ZRCOLA_API mapping_vector : public std::vector<mapping> {
|
||||
public:
|
||||
///
|
||||
/// Transforms character index of decomposed to composed string
|
||||
///
|
||||
/// \param[in] decmp Character index in decomposed string
|
||||
///
|
||||
/// \returns Character index in composed string
|
||||
///
|
||||
size_t to_composed(_In_ size_t decmp) const;
|
||||
|
||||
///
|
||||
/// Transforms destination index to source index
|
||||
///
|
||||
/// \param[in] cmp Character index in composed string
|
||||
///
|
||||
/// \returns Character index in decomposed string
|
||||
///
|
||||
size_t to_decomposed(_In_ size_t cmp) const;
|
||||
};
|
||||
};
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
@@ -31,6 +31,8 @@ void ZRCOLA_API ZRCola::Decompose(_In_z_count_(inputMax) const wchar_t *input, _
|
||||
// Since decomposition expands the string, let's keep our fingers crossed to avoid reallocation later.
|
||||
output.clear();
|
||||
output.reserve(inputMax * 2);
|
||||
if (map)
|
||||
map->clear();
|
||||
|
||||
for (size_t i = 0; i < inputMax;) {
|
||||
// Find whether the character can be decomposed.
|
||||
@@ -58,9 +60,4 @@ void ZRCOLA_API ZRCola::Decompose(_In_z_count_(inputMax) const wchar_t *input, _
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (map) {
|
||||
// Add final mapping.
|
||||
map->push_back(mapping(inputMax, output.length()));
|
||||
}
|
||||
}
|
||||
|
||||
70
lib/libZRCola/src/mapping.cpp
Normal file
70
lib/libZRCola/src/mapping.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright 2015-2016 Amebis
|
||||
|
||||
This file is part of ZRCola.
|
||||
|
||||
ZRCola is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ZRCola is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with ZRCola. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
size_t ZRCola::mapping_vector::to_composed(_In_ size_t decmp) const
|
||||
{
|
||||
for (size_type l = 0, r = size();;) {
|
||||
if (l < r) {
|
||||
size_type m = (l + r) / 2;
|
||||
const mapping &el = (*this)[m];
|
||||
|
||||
if (decmp < el.decmp) r = m;
|
||||
else if (el.decmp < decmp) l = m + 1;
|
||||
else {
|
||||
// An exact match found.
|
||||
return el.cmp;
|
||||
}
|
||||
} else if (l) {
|
||||
// We found a map interval.
|
||||
const mapping &el = (*this)[l - 1];
|
||||
return el.cmp + (decmp - el.decmp);
|
||||
} else {
|
||||
// The decomposed character index is far left.
|
||||
return decmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t ZRCola::mapping_vector::to_decomposed(_In_ size_t cmp) const
|
||||
{
|
||||
for (size_type l = 0, r = size();;) {
|
||||
if (l < r) {
|
||||
size_type m = (l + r) / 2;
|
||||
const mapping &el = (*this)[m];
|
||||
|
||||
if (cmp < el.cmp) r = m;
|
||||
else if (el.cmp < cmp) l = m + 1;
|
||||
else {
|
||||
// An exact match found.
|
||||
return el.decmp;
|
||||
}
|
||||
} else if (l) {
|
||||
// We found a map interval.
|
||||
const mapping &el = (*this)[l - 1];
|
||||
return el.decmp + (cmp - el.cmp);
|
||||
} else {
|
||||
// The composed character index is far left.
|
||||
return cmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
Submodule lib/wxExtend updated: 27edfa1a59...6914baf5b2
Reference in New Issue
Block a user