skia2/experimental/editor/run_handler.h
Hal Canary 66bf2cfb93 experimental/editor: progress on newlines
Editor:
  - Editor::Shape(): Place end-of-line cursor correctly.
  - Editor::insert(): Allow insertion of '\n' character.
  - Don't try to reshape empty string each time.
  - Editor::insert(), Editor::setText(): Validate utf8 input
  - Editor::remove(): Delete across newlines.
  - Editor::copy(): implement.
  - Editor::text() Iterator.

App:
  - Implement Ctrl-c, Ctrl-x, Ctr-v
  - Implement Ctrl-s
  - Handle "Enter" key as "insert '\n'"

StringSlice:
  - Cleanup, copy ctor.

Change-Id: I724edb82c93b30f4d5279f5a99036459a21ca2cd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222508
Auto-Submit: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2019-06-24 17:24:35 +00:00

62 lines
2.1 KiB
C++

// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#ifndef run_handler_DEFINED
#define run_handler_DEFINED
#include "include/core/SkPoint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkTypes.h"
#include "modules/skshaper/include/SkShaper.h"
class SkFont;
namespace editor {
class RunHandler final : public SkShaper::RunHandler {
public:
RunHandler(const char* utf8Text, size_t) : fUtf8Text(utf8Text) {}
using RunCallback = void (*)(void* context,
const char* utf8Text,
size_t utf8TextBytes,
size_t glyphCount,
const SkGlyphID* glyphs,
const SkPoint* positions,
const uint32_t* clusters,
const SkFont& font);
void setRunCallback(RunCallback f, void* context) {
fCallbackContext = context;
fCallbackFunction = f;
}
sk_sp<SkTextBlob> makeBlob();
SkPoint endPoint() const { return fOffset; }
float yOffset() const { return fOffset.y() - (fMaxRunDescent + fMaxRunLeading - fMaxRunAscent); }
void beginLine() override;
void runInfo(const RunInfo&) override;
void commitRunInfo() override;
SkShaper::RunHandler::Buffer runBuffer(const RunInfo&) override;
void commitRunBuffer(const RunInfo&) override;
void commitLine() override;
private:
SkTextBlobBuilder fBuilder;
const SkGlyphID* fCurrentGlyphs = nullptr;
const SkPoint* fCurrentPoints = nullptr;
void* fCallbackContext = nullptr;
RunCallback fCallbackFunction = nullptr;
char const * const fUtf8Text;
uint32_t* fClusters = nullptr;
int fClusterOffset = 0;
int fGlyphCount = 0;
SkScalar fMaxRunAscent = 0;
SkScalar fMaxRunDescent = 0;
SkScalar fMaxRunLeading = 0;
SkPoint fCurrentPosition = {0, 0};
SkPoint fOffset = {0, 0};
};
} // namespace editor
#endif // run_handler_DEFINED