add text ndk api

Signed-off-by: stella.ren <rencongyaxu@huawei.com>
This commit is contained in:
stella.ren 2022-02-21 22:44:22 -08:00
parent e48b21f9c6
commit 2389bfbe28
3 changed files with 21 additions and 14 deletions

View File

@ -218,7 +218,8 @@ void OH_Drawing_SetTextStyleFontHeight(OH_Drawing_TextStyle*, double /* fontHeig
* @param int number of font families
* @param char* fontFamilies name
*/
void OH_Drawing_SetTextStyleFontFamilies(OH_Drawing_TextStyle*, int /* fontFamiliesNumber */, const char* fontFamilies[]);
void OH_Drawing_SetTextStyleFontFamilies(OH_Drawing_TextStyle*,
int /* fontFamiliesNumber */, const char* fontFamilies[]);
/**
* @brief set typography font style.
@ -244,7 +245,8 @@ void OH_Drawing_SetTextStyleLocale(OH_Drawing_TextStyle*, const char*);
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @return a pointer to created OH_Drawing_TypographyCreate
*/
OH_Drawing_TypographyCreate* OH_Drawing_CreateTypographyHandler(OH_Drawing_TypographyStyle*, OH_Drawing_FontCollection*);
OH_Drawing_TypographyCreate* OH_Drawing_CreateTypographyHandler(OH_Drawing_TypographyStyle*,
OH_Drawing_FontCollection*);
/**
* @brief Release the memory storing the OH_Drawing_TypographyCreate object.
@ -314,7 +316,8 @@ void OH_Drawing_TypographyLayout(OH_Drawing_Typography*, double /* maxWidth */);
* @param double position X
* @param double position Y
*/
void OH_Drawing_TypographyPaint(OH_Drawing_Typography*, OH_Drawing_Canvas*, double /* potisionX */, double /* potisionY */);
void OH_Drawing_TypographyPaint(OH_Drawing_Typography*, OH_Drawing_Canvas*,
double /* potisionX */, double /* potisionY */);
#ifdef __cplusplus
}

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
#include "c/drawing_text_typography.h"
#include "c/drawing_text_convertor.h"
#include "c/drawing_text_typography.h"
#include "rosen_text/ui/font_collection.h"
#include "rosen_text/ui/typography.h"
#include "rosen_text/ui/typography_create.h"
@ -37,7 +37,7 @@ void OH_Drawing_DestroyTypographyStyle(OH_Drawing_TypographyStyle* style)
void OH_Drawing_SetTypographyTextDirection(OH_Drawing_TypographyStyle* style, int direction)
{
rosen::TextDirection textDirection;
switch(direction) {
switch (direction) {
case TEXT_DIRECTION_RTL: {
textDirection = rosen::TextDirection::RTL;
break;
@ -57,7 +57,7 @@ void OH_Drawing_SetTypographyTextDirection(OH_Drawing_TypographyStyle* style, in
void OH_Drawing_SetTypographyTextAlign(OH_Drawing_TypographyStyle* style, int align)
{
rosen::TextAlign textAlign;
switch(align) {
switch (align) {
case TEXT_ALIGN_LEFT: {
textAlign = rosen::TextAlign::LEFT;
break;
@ -217,7 +217,8 @@ void OH_Drawing_SetTextStyleFontHeight(OH_Drawing_TextStyle* style, double fontH
ConvertToOriginalText(style)->height_ = fontHeight;
}
void OH_Drawing_SetTextStyleFontFamilies(OH_Drawing_TextStyle* style, int fontFamiliesNumber, const char* fontFamilies[])
void OH_Drawing_SetTextStyleFontFamilies(OH_Drawing_TextStyle* style,
int fontFamiliesNumber, const char* fontFamilies[])
{
std::vector<std::string> rosenFontFamilies;
for (int i = 0; i < fontFamiliesNumber; i++) {

View File

@ -68,17 +68,19 @@ void DoDraw(uint8_t *addr, uint32_t width, uint32_t height, size_t index)
OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
OH_Drawing_CanvasBind(cCanvas, cBitmap);
OH_Drawing_CanvasClear(cCanvas,OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_LTR);
OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_LEFT);
OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle, OH_Drawing_CreateFontCollection());
OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
OH_Drawing_CreateFontCollection());
OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
OH_Drawing_SetTextStyleFontSize(txtStyle, 80);
double fontSize = 30;
OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
OH_Drawing_SetTextStyleFontHeight(txtStyle, 1);
@ -168,14 +170,15 @@ int main()
auto surfaceNode = CreateSurface();
RSDisplayNodeConfig config;
RSDisplayNode::SharedPtr displayNode = RSDisplayNode::Create(config);
for (size_t i = 0; i < 5; i++) {
sleep(2);
int testNumber = 5;
for (size_t i = 0; i < testNumber; i++) {
int restTime = 4;
sleep(restTime);
displayNode->AddChild(surfaceNode, -1);
surfaceNode->SetBounds(0, 0, WIDTH, HEIGHT);
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
DrawSurface(surfaceNode, WIDTH, HEIGHT, i);
// sleep 8s
sleep(4);
sleep(restTime);
displayNode->RemoveChild(surfaceNode);
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
}