Unverified Commit f1288f35 authored by Oleksandr Karpovich's avatar Oleksandr Karpovich Committed by GitHub

add commonMain/cpp for common bindings (js,native,jvm) (#345)

* add commonMain/cpp for common bindings (js,native,jvm)

* fix typo in FontRunIterator.cc #include
Co-authored-by: 's avatarOleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
parent aa466a74
......@@ -70,11 +70,12 @@ val compileWasm = tasks.register<CompileSkikoCppTask>("compileWasm") {
buildTargetArch.set(osArch.second)
buildVariant.set(buildType)
val srcDirs = projectDirs("src/jsMain/cpp", "src/nativeJsMain/cpp") +
val srcDirs = projectDirs("src/commonMain/cpp/common", "src/jsMain/cpp", "src/nativeJsMain/cpp") +
if (skiko.includeTestHelpers) projectDirs("src/nativeJsTest/cpp") else emptyList()
sourceRoots.set(srcDirs)
includeHeadersNonRecursive(projectDir.resolve("src/nativeJsMain/cpp"))
includeHeadersNonRecursive(projectDir.resolve("src/commonMain/cpp/common/include"))
includeHeadersNonRecursive(skiaHeadersDirs(skiaWasmDir.get()))
flags.set(listOf(
......@@ -149,11 +150,12 @@ fun registerNativeBridgesTask(os: OS, arch: Arch): TaskProvider<CompileSkikoCppT
else -> throw GradleException("$os not yet supported")
}
val srcDirs = projectDirs("src/nativeNativeJs/cpp", "src/nativeJsMain/cpp") +
val srcDirs = projectDirs("src/commonMain/cpp/common", "src/nativeNativeJs/cpp", "src/nativeJsMain/cpp") +
if (skiko.includeTestHelpers) projectDirs("src/nativeJsTest/cpp") else emptyList()
sourceRoots.set(srcDirs)
includeHeadersNonRecursive(projectDir.resolve("src/nativeJsMain/cpp"))
includeHeadersNonRecursive(projectDir.resolve("src/commonMain/cpp/common/include"))
includeHeadersNonRecursive(skiaHeadersDirs(unpackedSkia))
}
}
......@@ -544,6 +546,7 @@ val compileJvmBindings = tasks.register<CompileSkikoCppTask>("compileJvmBindings
buildVariant.set(buildType)
val srcDirs = projectDirs(
"src/commonMain/cpp/common",
"src/jvmMain/cpp/common",
"src/jvmMain/cpp/${targetOs.id}",
"src/jvmTest/cpp"
......@@ -553,6 +556,7 @@ val compileJvmBindings = tasks.register<CompileSkikoCppTask>("compileJvmBindings
includeHeadersNonRecursive(jdkHome.resolve("include"))
includeHeadersNonRecursive(skiaHeadersDirs(skiaJvmBindingsDir.get()))
includeHeadersNonRecursive(projectDir.resolve("src/jvmMain/cpp/include"))
includeHeadersNonRecursive(projectDir.resolve("src/commonMain/cpp/common/include"))
compiler.set(compilerForTarget(targetOs, targetArch))
......
#include <iostream>
#include <jni.h>
#include "../interop.hh"
#include "../TextLine.hh"
#include "TextLine.hh"
#include "SkShaper.h"
#include "SkTextBlob.h"
#include "unicode/ubrk.h"
......@@ -75,7 +73,7 @@ public:
// if one glyph includes multiple grapheme clusters (ligature, e.g. <->), accumulate
if ((glyph < info.glyphCount ? fGlyphOffsets[glyph] : info.utf8Range.end()) > offset)
++graphemesInGlyph;
// when boundaries meet, distribute break positions evenly inside glyph
else {
SkScalar glyphRight = glyph < info.glyphCount ? run.fPos[glyph].fX : fPosition + info.fAdvance.fX;
......@@ -130,4 +128,4 @@ private:
std::vector<uint32_t> fGlyphOffsets;
SkScalar fPosition = 0;
SkDEBUGCODE(int fLines = 0;)
};
\ No newline at end of file
};
......@@ -51,7 +51,7 @@ void FontRunIterator::consume() {
}
}
}
while (clusterStart < fEnd) {
clusterStart = clusterEnd;
clusterEnd = fBegin + ubrk_following(fGraphemeIter.get(), clusterStart - fBegin);
......
#pragma once
#include "SkShaper.h"
#include "unicode/ubrk.h"
#include "unicode/utext.h"
class FontRunIterator final: public SkShaper::FontRunIterator {
public:
FontRunIterator(const char* utf8,
size_t utf8Bytes,
const SkFont& font,
sk_sp<SkFontMgr> fallbackMgr,
const char* requestName,
SkFontStyle requestStyle,
const SkShaper::LanguageRunIterator* lang,
std::shared_ptr<UBreakIterator> graphemeIter,
bool approximateSpaces,
bool approximatePunctuation)
: fCurrent(utf8)
, fBegin(utf8)
, fEnd(fCurrent + utf8Bytes)
, fFallbackMgr(std::move(fallbackMgr))
, fFont(font)
, fFallbackFont(fFont)
, fCurrentFont(nullptr)
, fRequestName(requestName)
, fRequestStyle(requestStyle)
, fLanguage(lang)
, fGraphemeIter(graphemeIter)
, fApproximateSpaces(approximateSpaces)
, fApproximatePunctuation(approximatePunctuation)
{
fFont.setTypeface(font.refTypefaceOrDefault());
fFallbackFont.setTypeface(nullptr);
}
FontRunIterator(const char* utf8,
size_t utf8Bytes,
const SkFont& font,
sk_sp<SkFontMgr> fallbackMgr,
std::shared_ptr<UBreakIterator> graphemeIter,
bool approximateSpaces,
bool approximatePunctuation)
: FontRunIterator(utf8,
utf8Bytes,
font,
std::move(fallbackMgr),
nullptr,
font.refTypefaceOrDefault()->fontStyle(),
nullptr,
graphemeIter,
approximateSpaces,
approximatePunctuation) {
}
~FontRunIterator() {
}
void consume() override;
size_t endOfCurrentRun() const override {
return fCurrent - fBegin;
}
bool atEnd() const override {
return fCurrent == fEnd;
}
const SkFont& currentFont() const override {
return *fCurrentFont;
}
private:
char const * fCurrent;
char const * const fBegin;
char const * const fEnd;
sk_sp<SkFontMgr> const fFallbackMgr;
SkFont fFont;
SkFont fFallbackFont;
SkFont* fCurrentFont;
char const * const fRequestName;
SkFontStyle const fRequestStyle;
SkShaper::LanguageRunIterator const * const fLanguage;
std::shared_ptr<UBreakIterator> fGraphemeIter;
bool fApproximateSpaces;
bool fApproximatePunctuation;
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment