Skip to content

Commit

Permalink
Merge pull request #7 from extio1/dev
Browse files Browse the repository at this point in the history
Model and Controller MVP done
  • Loading branch information
extio1 authored Jun 9, 2024
2 parents 3af8243 + bce0c38 commit 8d10113
Show file tree
Hide file tree
Showing 66 changed files with 5,401 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4
20 changes: 0 additions & 20 deletions .github /workflows/on_pull_request.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: build

on:
pull_request:
branches:
- 'release'
- 'dev'

jobs:
download-dependencies:
runs-on: ubuntu-latest
steps:
- run: mkdir install-artifacts
- name: Download dependencies
run: |
wget https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_0.tar.gz
- name: Save artifacts
uses: actions/upload-artifact@v4
with:
name: dependencies-artifact
path: boost_1_80_0.tar.gz

build:
needs: [download-dependencies]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dependencies-artifact

- name: Install Boost
run: |
tar -xzf boost_1_80_0.tar.gz
cd boost_1_80_0
./bootstrap.sh --with-libraries=serialization
sudo ./b2 install
- name: Build project
run: |
mkdir build
cmake -Bbuild
cmake --build build
- name: Save artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: build

test:
needs: [build, download-dependencies]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build-artifacts
path: build
- uses: actions/download-artifact@v4
with:
name: dependencies-artifact

- name: Install Boost
run: |
tar -xzf boost_1_80_0.tar.gz
cd boost_1_80_0
./bootstrap.sh --with-libraries=serialization
sudo ./b2 install
- name: Add lanch permissions for text executables
run: |
chmod +x build/test/model/*
chmod +x build/test/controller/*
- name: Run tests
run: GTEST_COLOR=1 ctest -V --test-dir build/
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#vscode config
.vscode/*
.vscode/settings.json

# Prerequisites
*.d

Expand Down Expand Up @@ -33,3 +37,7 @@

# Build
build/*
cmake-build-debug/*

# idea configs
.idea/*
71 changes: 71 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"files.associations": {
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
}
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.14)
project(text_editor_project)

set(target text_editor)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(include_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_subdirectory(src)
enable_testing()
add_subdirectory(test)

add_executable(${target} main.cpp)
target_include_directories(${target} PUBLIC ${include_dir})

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${target} PRIVATE -Wall -Wextra -Wconversion -pedantic -g)
endif()

target_link_libraries(${target} executor document point compositor)
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Installation

```console
mkdir build; cd build
cmake ..
cmake --build .
```

# Usage
As result of the build executables are available (in `build`):
1. `text_editor` - executable with entry point in main.c
2. `test/model/model_test` - google tests for model
11 changes: 11 additions & 0 deletions devops/format-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

for file in `find ../include -type f | grep -i -E '\.(cpp|h|c|hpp)$'`; do
clang-format -style=file -i ${file}
echo ${file} ": formatted"
done

for file in `find ../src -type f | grep -i -E '\.(cpp|h|c|hpp)$'`; do
clang-format -style=file -i ${file}
echo ${file} ": formatted"
done
6 changes: 6 additions & 0 deletions devops/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

for file in `git diff --staged --name-only | grep -i -E '\.(cpp|h|c|hpp)$'`; do
clang-format -style=file -i ${file}
git add ${file}
done
74 changes: 74 additions & 0 deletions include/compositor/compositor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef TEXT_EDITOR_COMPOSITOR_H_
#define TEXT_EDITOR_COMPOSITOR_H_

#include <iostream>
#include <boost/serialization/export.hpp>
#include <boost/serialization/access.hpp>

#include "document/document.h"

class Compositor {
public:
enum Alignment { LEFT, CENTER, RIGHT, JUSTIFIED };

Compositor() {
document = nullptr;
this->topIndent = 5;
this->bottomIndent = 10;
this->leftIndent = 3;
this->rightIndent = 6;
this->alignment = LEFT;
this->lineSpacing = 3;
}

Compositor(int topIndent, int bottomIndent, int leftIndent,
int rightIndent, Alignment alignment,
int lineSpacing) {
document = nullptr;
this->topIndent = topIndent;
this->bottomIndent = bottomIndent;
this->leftIndent = leftIndent;
this->rightIndent = rightIndent;
this->alignment = alignment;
this->lineSpacing = lineSpacing;
}

virtual ~Compositor() = default;

void SetDocument(Document* document);

virtual void Compose() = 0;

void SetTopIndent(int value);
void SetBottomIndent(int value);
void SetLeftIndent(int value);
void SetRightIndent(int value);
void SetAlignment(Alignment value);
void SetLineSpacing(int value);

protected:
Document* document;

int topIndent;
int bottomIndent;
int leftIndent;
int rightIndent;
Alignment alignment;
int lineSpacing;

private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
std::cout << "0 Compositor\n";
ar & document;
ar & topIndent & bottomIndent & leftIndent;
ar & rightIndent & alignment & lineSpacing;
std::cout << "1 Compositor\n";
}

};
BOOST_CLASS_EXPORT_KEY(Compositor)

#endif // TEXT_EDITOR_COMPOSITOR_H_
53 changes: 53 additions & 0 deletions include/compositor/simple_compositor/simple_compositor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef TEXT_EDITOR_SIMPLECOMPOSITOR_H_
#define TEXT_EDITOR_SIMPLECOMPOSITOR_H_

#include <iostream>
#include <boost/serialization/export.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/base_object.hpp>

#include "compositor/compositor.h"
#include "document/document.h"

class SimpleCompositor : public Compositor {
public:
explicit SimpleCompositor()
: Compositor(5, 10, 3, 6,
LEFT, 5) {}

explicit SimpleCompositor(int topIndent, int bottomIndent,
int leftIndent, int rightIndent,
Alignment alignment, int lineSpacing)
: Compositor(topIndent, bottomIndent, leftIndent, rightIndent,
alignment, lineSpacing) {}

~SimpleCompositor() override = default;

void Compose() override;

private:
void ComposePage(Page::PagePtr& page, GlyphContainer::GlyphList& list);
void ComposeColumn(Glyph::GlyphPtr& column, int x, int y, int width,
int height, GlyphContainer::GlyphList& list);
void ComposeRow(Glyph::GlyphPtr& row, int x, int y, int width,
GlyphContainer::GlyphList& list);
void ComposeCharacter(Glyph::GlyphPtr& character, int x, int y);

size_t GetNestedGlyphsCount(Glyph::GlyphPtr& glyph);
int GetNestedGlyphsWidth(Glyph::GlyphPtr& glyph);
int GetNestedGlyphsHeight(Glyph::GlyphPtr& glyph);

GlyphContainer::GlyphList CutAllCharacters();

friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
std::cout << "0 SimpleCompositor\n";
ar & boost::serialization::base_object<Compositor>(*this);
std::cout << "1 SimpleCompositor\n";
}
};
BOOST_CLASS_EXPORT_KEY(SimpleCompositor)

#endif // TEXT_EDITOR_SIMPLECOMPOSITOR_H_
Loading

0 comments on commit 8d10113

Please sign in to comment.